File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with static method..

 
Max White
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a piece of code i tried but couldn't get the reason for the output..

Output is :

How could class B access the static method of class A?Is it a form of hiding?If yes,then what kind of ?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12016
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because anything that is a 'B' IS-AN 'A'.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A very similar question came up recently at the end of this thread.

It is a bit like hiding, yes, only in reverse. The show() method belongs to class A and class B doesn't actually have a show() method. There is only a show() method in A so that is what the compiler will have gone for.
 
Max White
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell but y doesn't the compiler flag this as an error?
As we all know,static method belongs to a class.In this case it belongs to class A,then how can we access it using the subclass(B)?
And to be honest, i din get fred....

anything that is a 'B' IS-AN 'A'.


i guess here i m talking about something which belongs to A,so it might not belong to B.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rules of inheritance: if "B extends A" then a "B" is-a[n] "A." We say inheritance implies an "IS-A" relationship.

The features of "A" (exception constructors) are repeated in "B."

Imaging you have Vehicle which is extended by Car. Then a Car IS-A Vehicle, and any features of Vehicle can reappear in Car.
 
Max White
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,i got it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Max White:
Thanks,i got it.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic