⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 refdemo.java

📁 it is a good tool to help you study java
💻 JAVA
字号:
class Box{
double width;
double heigth;
double depth;
Box(Box ob){
width=ob.width;
heigth=ob.heigth;
depth=ob.depth;
}
Box(double w,double h,double d){
width=w;
heigth=h;
depth=d;
}
Box(){
width=-1;
heigth=-1;
depth=-1;
}
Box(double len){
width=depth=heigth=len;
}
double vulume(){

return width*depth*depth;
}}
class BoxWeight extends Box{
double weight;
BoxWeight(double w,double h,double d,double m){
width=w;
heigth=h;
depth=d;
weight=m;
}
}
class RefDemo{
public static void main(String args[]){
BoxWeight weightbox=new BoxWeight(3,5,7,8.37);
Box plainbox=new Box();
double vol;
vol=weightbox.vulume();
System.out.println("Volume of weightbox is "+vol);
System.out.println("Weight of weightbox is"+weightbox.weight);
System.out.println();
plainbox=weightbox;
vol=plainbox.vulume();
System.out.println("volume of blainbox is "+vol);
//System.out.println("weight of plainbox is"+plainbox.weight);
//由于超类不知道子类增加的属性,所以不能用超类对象的引用来给子类对象的引//用赋值
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -