3. class Mammal {
4. String name = "furry ";
5. String makeNoise() { return "generic noise"; }
6. }
7. class Zebra extends Mammal {
8. String name = "stripes ";
9. String makeNoise() { return "bray"; }
10. }
11. public class ZooKeeper {
12. public static void main(String[] args) { new ZooKeeper().go(); }
13. void go() {
14. Mammal m = new Zebra();
15. System.out.println(m.name + m.makeNoise());
16. }
17. }
What is the result?
A. furry bray
B. stripes bray
C. furry generic noise
D. stripes generic noise
E. Compilation fails
F. An exception is thrown at runtime
Mammal m = new Zebra();
--
You received this message because you are subscribed to the Google Groups "IndiJava - India Java User Group & Java Community." group.
To post to this group, send email to indi...@googlegroups.com
To unsubscribe from this group, send email to indijava-u...@googlegroups.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.indijava.in - India Java User Group & Java Community.
http://groups.google.com/group/indijava/
Java Fresher Jobs : http://www.indijava.in/community/fresher-jobs
Quiz : http://www.indijava.in/community/QUIZ
Java News: http://www.indijava.in/community/java-news
Tutorials: http://www.indijava.in/community/tutorials
Forum http://www.indijava.in/community/forum
SCJP Resources : http://www.indijava.in/community/category/certifications/scjp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
On Dec 17, 10:24 am, Vishal Kukreja <vishalkukrej...@gmail.com> wrote:
> In ZooKeeper class:
> void go()
> {
>
> Mammal m = new Zebra();
>
> System.out.println(m.name + m.makeNoise());
>
> }
>
> Here Reference Mammal is given, but polymorphically(with reference of
> Mammal) it refers to a Mammal Subclass instance (Zebra in this case). So
> at run-time object(zebra) will run its own makeNoise() method. So result
> of m.makeNoise():*bray*
> (This case is applied to Methods at runtime)
>
> About m.name: it's calling 'name' of superclass only.
> Java Guru's, correct me if I am wrong.
>
> 2011/12/17 Murad İmanbəyli <muradimanba...@gmail.com>
> >http://www.indijava.in- India Java User Group & Java Community.
> >http://groups.google.com/group/indijava/
>
> > Java Fresher Jobs :http://www.indijava.in/community/fresher-jobs
> > Quiz :http://www.indijava.in/community/QUIZ
> > Java News:http://www.indijava.in/community/java-news
> > Tutorials:http://www.indijava.in/community/tutorials
> > Forumhttp://www.indijava.in/community/forum
> > SCJP Resources :
> >http://www.indijava.in/community/category/certifications/scjp
>
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> --
>
> Regards,
> <http://goog_968477932>Vishal Kukreja
On 17 Aralık, 10:24, Vishal Kukreja <vishalkukrej...@gmail.com> wrote:
> In ZooKeeper class:
> void go()
> {
>
> Mammal m = new Zebra();
>
> System.out.println(m.name + m.makeNoise());
>
> }
>
> Here Reference Mammal is given, but polymorphically(with reference of
> Mammal) it refers to a Mammal Subclass instance (Zebra in this case). So
> at run-time object(zebra) will run its own makeNoise() method. So result
> of m.makeNoise():*bray*
> (This case is applied to Methods at runtime)
>
> About m.name: it's calling 'name' of superclass only.
> Java Guru's, correct me if I am wrong.
>
> 2011/12/17 Murad İmanbəyli <muradimanba...@gmail.com>
> >http://www.indijava.in- India Java User Group & Java Community.
> >http://groups.google.com/group/indijava/
>
> > Java Fresher Jobs :http://www.indijava.in/community/fresher-jobs
> > Quiz :http://www.indijava.in/community/QUIZ
> > Java News:http://www.indijava.in/community/java-news
> > Tutorials:http://www.indijava.in/community/tutorials
> > Forumhttp://www.indijava.in/community/forum
> > SCJP Resources :
> >http://www.indijava.in/community/category/certifications/scjp
>
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> --
>
> Regards,
> <http://goog_968477932>Vishal Kukreja
On Dec 17, 10:24 am, Vishal Kukreja <vishalkukrej...@gmail.com> wrote:
> In ZooKeeper class:
> void go()
> {
>
> Mammal m = new Zebra();
>
> System.out.println(m.name + m.makeNoise());
>
> }
>
> Here Reference Mammal is given, but polymorphically(with reference of
> Mammal) it refers to a Mammal Subclass instance (Zebra in this case). So
> at run-time object(zebra) will run its own makeNoise() method. So result
> of m.makeNoise():*bray*
> (This case is applied to Methods at runtime)
>
> About m.name: it's calling 'name' of superclass only.
> Java Guru's, correct me if I am wrong.
>
> 2011/12/17 Murad İmanbəyli <muradimanba...@gmail.com>
> >http://www.indijava.in- India Java User Group & Java Community.
> >http://groups.google.com/group/indijava/
>
> > Java Fresher Jobs :http://www.indijava.in/community/fresher-jobs
> > Quiz :http://www.indijava.in/community/QUIZ
> > Java News:http://www.indijava.in/community/java-news
> > Tutorials:http://www.indijava.in/community/tutorials
> > Forumhttp://www.indijava.in/community/forum
> > SCJP Resources :
> >http://www.indijava.in/community/category/certifications/scjp
>
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> --
>
> Regards,
> <http://goog_968477932>Vishal Kukreja