ClassLevel{Stringname=””;intheight,width;publicLevel(){;}{name=le.name;height=le.height;width=le.width;}publicLevel(Stringna,inth,intw){name=na;height=h;width=w;}
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.”);
}
}
展开
本文发布于:2024-02-02 08:03:19,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170683220042459.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |