Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

upcasting and downcasting

843785Nov 19 2008 — edited Nov 19 2008
hi
can any one tell me

1)what is upcasting and downcasting?
2)class SuperClass{
public void show(){System.out.println("super");}
}
class SubClass extends SuperClass{
public void show(){System.out.println("sub");
}
public void m1(){
System.out.println("m1()");
}
public static void main(String s[]){
SuperClass s1=new SubClass();
s1.show();// output---- sub
s1.m1();// it will give error
}

}

can any one tell me how can i call sub class m1() using s1 reference.

thansk in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2008
Added on Nov 19 2008
3 comments
203 views