aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes I need to help with the question 13 chapter 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "I need to help with the question 13 chapter 2" Watch "I need to help with the question 13 chapter 2" New topic
Author

I need to help with the question 13 chapter 2

Mauricio Archbold Babroza
Greenhorn

Joined: Apr 01, 2009
Posts: 11
why is the result "furry bray" and is not "furry generic noise"???

Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Because members variables never inherited and do not behave in polymorphic way.

Both the classes have variable with same name and you are assigning a child reference to parent object. So the instance member of the referring (Parent class) class will be called and method of the original underlying class (Child class) will be called.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3220
    
  49

Mauricio Archbold Babroza wrote:I need to help with the question 13 chapter 2

Is it from K&B Study Guide? Please quote the source properly.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
there is one very simple rule about this: Methods are called based on object while static methods & members variables are called based on reference.
Now you wrote

here reference is of Mammal while object is of Zebra so
will call Mammal variable &
will call zebra noise method


Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

will call Mammal variable &
view plaincopy to clipboardprint?



m.name will call zebra noise method


i think you want to say


Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Yep, for sure. I changed makeNoise() to static in both classes,
as demanded by the compiler, and the output became, "furry
generic noise." Mauricio Archbold Babroza, are you there?

Jim ... ...


BEE MBA PMP SCJP-6
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: I need to help with the question 13 chapter 2