• Post Reply Bookmark Topic Watch Topic
  • New Topic

static and non-static methods inheritance  RSS feed

 
Vinod Vijay
Ranch Hand
Posts: 165
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A child class extends a parent class by inheriting all its members i.e. instance variables and methods.
Can a child class also inherits a static methods?
I think yes, I tried and it worked.



 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinod Vijay wrote:A child class extends a parent class by inheriting all its members i.e. instance variables and methods.
Can a child class also inherits a static methods?
I think yes, I tried and it worked.

So, there's your answer.
It should be pointed out that you can't override static methods though, you can only mask them.

Also, using an object (in your case 'tc') to run a static method is a bit misleading (and some of us wish that Java hadn't allowed it).

you should almost always use the class name: ie, TestCompany.display(), NOT tc.display().

HIH

Winston
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It’s all in the Java Language Specification.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!