Hi all I hope this is clear here, this is an example from JLS with some additions..
class Super
{
int x=10;
static
String greeting() { return "overridden static method"; }
String name() { return "overridden instance method "; }
}
class Sub extends Super
{
float x=20.0f;
static String greeting() { return "overriding static method"; }
String name() { return "overriding instance method "; }
}
class
Test {
public static void main(String[] args)
{
Super s1 = new Sub();
Sub s2=new Sub();
System.out.println(s1.greeting() + ", " + s1.name()); 1
System.out.println(s2.greeting() + ", " + s2.name()); 2
System.out.println(s1.x); 3
System.out.println(s2.x); 4
}
}
here are the outputs
1. overridden static method,overiding instance method
2. overriding static method,overiding instance method
3.10
4. 20.0
In overriding instance variables and static members are considered as hidden not as overridden, hence a variable of type superclass ( it is referencing to an object of subclass type or of super class type. s1 in the Ex. )
always invokes members of super class if they are 1. static methods and static variables
2. Instance variables
and always invokes members of sub class if they are 1. Instacnce methods.
can please some one mail me how to use HTML tags to post a mesg.
thanks& regds.
vb_reddy@yahoo.com [This message has been edited by vb reddy (edited October 19, 2000).]
[This message has been edited by vb reddy (edited October 19, 2000).]
[This message has been edited by vb reddy (edited October 19, 2000).]