wood burning stoves 2.0*
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
Author

Question on inheritence

Jitender kumar
Greenhorn

Joined: Aug 10, 2004
Posts: 12
Hi,
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
Sheriff

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
sscce.org
Jitender kumar
Greenhorn

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
Greenhorn

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.


Chandu.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on inheritence
 
Similar Threads
Confuse in static block
How can I get access to methods in other classes
Doubt regarding static and main
EJB 3: Dynamic Element Values
Session Utility class