aspose file tools*
The moose likes Beginning Java and the fly likes Overriding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Overriding?" Watch "Overriding?" New topic
Author

Overriding?

Mauro Trevigno
Ranch Hand

Joined: Aug 27, 2012
Posts: 40

Hi Guys,






I know a method that is declared final in the super class cannot be overridden. Methods that are declared private or static cannot be overridden either because they are implicitly final. It is also impossible for a class that is declared final to become a super class.

I dont have any final, private, static method.. or println is considered as static??

Thank You!

Regards,
-M
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I don't understand your questions. The method go() in Frame overrides the method go() in Clip perfectly well. This has nothing to do with the fact that SuperBike extends Bike; I'm not sure what you think should be different between the Bike and SuperBike parts. Can you tell us what you were expecting, and then maybe we could explain what the issue is?

Then as far as your last question, no, println() isn't static; it's an instance method of the PrintStream class(System.out is a PrintStream.) I don't understand how this is related to the rest of the problem so again, perhaps you could explain your question a bit better.


[Jess in Action][AskingGoodQuestions]
Mauro Trevigno
Ranch Hand

Joined: Aug 27, 2012
Posts: 40

Ernest Friedman-Hill wrote:I don't understand your questions. The method go() in Frame overrides the method go() in Clip perfectly well. This has nothing to do with the fact that SuperBike extends Bike; I'm not sure what you think should be different between the Bike and SuperBike parts. Can you tell us what you were expecting, and then maybe we could explain what the issue is?

Then as far as your last question, no, println() isn't static; it's an instance method of the PrintStream class(System.out is a PrintStream.) I don't understand how this is related to the rest of the problem so again, perhaps you could explain your question a bit better.



I expected sb.m.go(); and b.m.go() to print "Clip" and not "Frame".

Thanks!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Mauro Trevigno wrote:
I expected sb.m.go(); and b.m.go() to print "Clip" and not "Frame".


The variable m always holds an instance of Frame, so calling go() on it always calls Frame's version of go(); it's as simple as that. Why did you think it would print "Clip" ?
shivamahesh bachu
Greenhorn

Joined: Sep 14, 2012
Posts: 13
I expected sb.m.go(); and b.m.go() to print "Clip" and not "Frame".

Mauro Trevigno,

Firstly, we are creating an object for Frame
Secondly, we are refering to go() of 'Frame' class using Frame object i.e., m
So it is obvious that the output would be 'Frame' but not 'Clip'

For more info.
check this out
http://javaeschool.com/java-tutorials/method-overriding-in-java/

Thanks,
Mahesh.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Mauro Trevigno wrote: . . . Methods that are declared private or static cannot be overridden either because they are implicitly final. . . . or println is considered as static?? . . .
As for println, you should look at its documentation, which will tell youwhether it is static. It is also worthwhile finding out whether this is static.
You are mistaken about methods being implicitly final. Unlike in C++, there is no such thing as implicitly final. The reason you cannot override static or private methods is that something different happens: look at this FAQ, for a start.
When I ride my bicycle, I never think a clip would be a frame, so why do you have a frame class which extends clip? Also why are you not making all the fields in your classes final?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Welcome to the Ranch, shivamahesh bachu.

Please note this, which is from the title page for this forum.
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
By providing a “more exact answer”, you are liable to excuse people from the effort of doing things for themselves, and reduce their chances to learn. As well as getting the answer, looking at those links would have helped others to learn how to use the API documentation. Please beware of giving such answers in future.
Mauro Trevigno
Ranch Hand

Joined: Aug 27, 2012
Posts: 40

Ernest Friedman-Hill wrote:
Mauro Trevigno wrote:
I expected sb.m.go(); and b.m.go() to print "Clip" and not "Frame".


The variable m always holds an instance of Frame, so calling go() on it always calls Frame's version of go(); it's as simple as that. Why did you think it would print "Clip" ?


Thanks I got it!

Well Im just trying to move and do my code in different ways, to understand how it works!

Thanks Guys!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Overriding?