A sentimental robot

Inheritance exercise(1) 본문

Java

Inheritance exercise(1)

GOD03219 2017. 12. 29. 10:23

public class AA {

 private String str;
 
 public void setStr(String str){
  this.str=str;
 }
 public String getStr(){
  return str;
  
 }
}


 


 


public class BB extends AA{
 private int aa;

 

 public void setAa(int aa) {
  this.aa = aa;
 }

 public int getAa() {
  return aa;
 }

}


 


 


public class CC extends BB{

 
 public static void main(String []args){
  
  CC cc=new CC();
  
  cc.setStr("Superman");
  cc.setAa(1000);
  System.out.println(cc.getStr());
  System.out.println(cc.getAa());
  

  
 }
}

'Java' 카테고리의 다른 글

Overridding, 재정의  (0) 2017.12.29
Inheritance exercise(2)  (0) 2017.12.29
Is~a 상속관계  (0) 2017.12.29
Extended.ver  (0) 2017.12.28
"Has~A" exercise  (0) 2017.12.28