Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Parent{
- int x=100;
- void method(){
- System.out.println("Parent Method");
- }
- }
- class Child extends Parent{
- int x=200;
- void method(){
- System.out.println("Child Method");
- }
- }
- public class practice {
- public static void main(String[] args) throws InterruptedException{
- Parent a = new Child();
- Child b=null;
- b=(Child)a; //down casting 형 변환해야함
- Parent c=null;
- Child d=new Child();
- c=d; //up casting 형변환 생략가능
- //-----------------------------------------//
- Parent p = new Child();
- Child q =new Child();
- System.out.println("p.x = "+p.x);
- p.method();
- System.out.println("c.x = "+q.x);
- c.method();
- }
- }
Add Comment
Please, Sign In to add comment