Tuesday, February 24, 2009

source code to demonstrate method hiding



// super class ,sub class static methods
package oops;
class Pc
{
static void m1(){
System.out.println("parent");
}
}
class C extends Pc
{
static void m1(){
System.out.println("child");
}
}
public class Sample {
public static void main(String[] ar)
{
Pc p=new C();
p.m1(); //parent m1
// method execution based on the reference type in method hiding
// method execution based on the object type in method overriding
}
}



1 comments:

Anonymous said...

Pc p=new C();
C is class name wrong try to execute

Post a Comment