• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overriding?

 
Ranch Hand
Posts: 99
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mauro Trevigno
Ranch Hand
Posts: 99
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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" ?
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 99
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic