This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

static and non-static methods inheritance  RSS feed

 
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.



 
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
 
Marshal
Posts: 58345
178
  • 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!