File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on inheritence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on inheritence" Watch "Question on inheritence" New topic

Question on inheritence

Jitender kumar

Joined: Aug 10, 2004
Posts: 12
Is inheritence of a class confined only to the non-static members functions of a class or static functions too?

Jitender Kumar Ch.V.<br /> <br />Nothing great can be achieved without true effort.
marc weber

Joined: Aug 31, 2004
Posts: 11343

static members are inherited, but static methods cannot be overridden.

You should write some code to test this.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Jitender kumar

Joined: Aug 10, 2004
Posts: 12
I could not find this statement in K&B book and so, I thought I would point out. Sorry, if I overlooked into the book.
chandu sekhar

Joined: Apr 22, 2004
Posts: 4
hi jitender,

for more clarification, a small example :

package mypackage;

class Parent
//Parent(String str){}
public static void XYZ(){ System.out.println("Parent XYZ");}


public class Child extends Parent
public static void XYZ(){System.out.println("Child XYZ");}
public static void main(String[] args)
Parent ch = new Child();
ch.XYZ(); // Special Line


if u change the statement at special line

1. Parent ch = new Child();
ch.XYZ(); // Special Line

Output is ----> Parent XYZ

2. Parent ch = new Child();
Parent.XYZ(); // Special Line

Output is -----> Parent XYZ

3. Child ch = new Child();
Child.XYZ(); // Special Line

Output is -----> Child XYZ

try some more combinations, so that u can understand better. hope it helps.

I agree. Here's the link:
subject: Question on inheritence
It's not a secret anymore!