JAVA공부하기87

상속의 이해

 

public class Ant

{

private String name="Ant";

public String getName()

{ return name; }

public String toString()

{ return "이름 : "+name;}

public void pring()

{ System.out.println(name+"은 동굴에 산다.") }

}

 

public class WaterAnt extends Ant

{

private String where="water";

public void show()

{ System.out.println(where+"주변"); }

public void print()

{ System.out.println(getName()+"은 "+where+"에 산다."); }

}

 

public class WaterAntMain

{

public static void main(String[] args)

{

Ant ant=new Ant();

ant.print();

System.out.println(ant.toString());

 

WaterAnt sant=new WaterAnt();

want.print();

want.show();

System.out.println(want.toString());

}

}

 

 

 

WaterAnt want=new WaterAnt();

 

 

 

 

 

Ant ant1 = new Ant();

 

 

WanterAnt want= new WanterAnt();

+ Recent posts