File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg:Override and redefine 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 "Reg:Override and redefine" Watch "Reg:Override and redefine" New topic
Author

Reg:Override and redefine

prema venkat
Greenhorn

Joined: Sep 27, 2006
Posts: 14
hai all,
i cant understand the difference between override and redefine of a sstatic method.
we know static cant be override but we can redefine in subclass means what it mean?

for example:
class Animal
{
static void daStuff() //Line 1
{
System.out.println("a");
}
}
class Dog extends Animal{
static void daStuff() //line2
{
System.out.println("d");
}
public static void main(String arg[])
{
Animal[] a={new Animal(),newDog(),newAnimal());
for(int x=0;x<a.length;x++)
a[x].doStuff();

}
}

Here line 2 seems like an override of line 1 but in the defination of this program it seems like line2 is redefinition not override.(coz static)

Please clear by doubt that how the redefinition differs from override coz its having same modifier and return type as like override.

Thanks in advance
Chris Stann
Ranch Hand

Joined: Oct 10, 2006
Posts: 49
Page 98, Chapter 2 of our famous SCJP book explains it well, I think: "Polymorphic method invocations apply only to instance methods. You can always refer to an object with a more general reference variable type (a superclass or interface), but at runtime, the ONLY things that are dynamically selected based on the actual object (rather than the reference type) are instance methods. Not static methods. Not variables. Only overridden instance methods are dynamically invoked based on the real object's type."


EXCEL IN ALL YOU DO
prema venkat
Greenhorn

Joined: Sep 27, 2006
Posts: 14
Thanks Chris.Now i am clear with this.
Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126

Hi Prema,

as you know, static is per class.

Overriding is the concept of polymorphism which can be applied to objects.

So the Animal class' doStuff belongs to that class only and Dog class' doStuff belongs to that class.

Even the object of Dog dont have a idea of the Animal class' doStuff method

Thats why its called redefinition

Hope you got the point

cheers
Guru


Thanks, Shiv
SCJP, OCE - JSP & Servlets Developer
prema venkat
Greenhorn

Joined: Sep 27, 2006
Posts: 14
Yes Guru.I got the point.Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reg:Override and redefine