ClassLevel{Stringname=””;intheight,width;publicLevel(){;}{name=le.name;height=le.height;width=le.width;}publicLevel(Stringna,inth,intw){name=na;height=h;width=w;}public...
Class Level
{String name=””;
int height,width;
public Level(){;}
{name=le.name;
height=le.height;
width=le.width; }
public Level(String na,int h,int w)
{name=na;
height=h;
width=w;}
public int higherthen(Level t)
{return this.height-t.height;}
public void print()
{System.out.println(“class Level:”);
System.out.println(“Name=;”+name+”,Height=;”+height+”,Width=;”+width);}
}
Class Leve2 extends Level
{int width;
public Leve2(){;}
public Leve2(Level le, int h,int w)
{super(le);
height=h;
width=w;}
public int widerthen()
{return width-super.width;}
public void print()
{System.out.println(“class Leve2:”);
System.out.println(“Name=;”+name+”,Height=;”+height+”,Width=;”+width);}
}
Public class Lev_ex
{ public static void main(String args[])
{Level le1=new Leve1(“Tower_1”,50,20);
Leve2 le2=new Leve2(le1,40,25);
Le1.print();
Le2.print();
System.out.println(“Level is”+le1.higherthen(le2)+”highter then Leve2.”);
System.out.println(“Level is”+le2.widerthen()+”wider then Level.”);
}
}
展开