wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Problem on Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem on Inheritance" Watch "Problem on Inheritance" New topic
Author

Problem on Inheritance

Chaturaka Gunatilaka
Greenhorn

Joined: Oct 06, 2012
Posts: 16


When I executed the code,I got the output as Sub.myMethod 0.But I was expecting Sub.myMethod 200.What went wrong?Why am I wrong?Thank you.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7505
    
  18

Chaturaka Gunatilaka wrote:When I executed the code,I got the output as Sub.myMethod 0. But I was expecting Sub.myMethod 200.What went wrong?Why am I wrong?

Won't tell you that, you need to ShowSomeEffort (←click); but I will ask you this:
What happens when new Sub() gets executed? EXACTLY. If you're not sure, look it up (you may find some useful stuff here) and write it down. Then apply it to your problem and see what you come up with.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem on Inheritance
 
Similar Threads
Overriding doubt ?
Invoking a Superclass Version of an Overridden Method
instance initializers
Strange recursive method call! ???
Super in static