Object Oriented

class superClass{
int x=111;
void xxx(){System.out.println("this is super class "+x);}
}
public class Fun extends superClass{
void xxx(){System.out.println("this is sub class "+x);}
int x=222;
public static void main(String[] args){
superClass f=new Fun();
System.out.println(f.x);
f.xxx();
//superClass f1=new superClass();
//Fun aa=(Fun)f1;//Class cast Exception
Fun a=(Fun)f;
//Fun a=new Fun();//Above line is considered as this line
System.out.println(a.x);
a.xxx();
}
}

OUTPUT:
111
this is sub class 222
222
this is sub class 222

No comments:

Post a Comment