📄 testconstructor1.java
字号:
class Cat {
private float weight;
private String color;
public String getColor(){
return color;
}
public float getWeight(){
return weight;
}
Cat(String s){
color=s;
System.out.println("It's a "+ s+" cat.");
}
Cat(String s,float w){
color=s;
weight=w;
System.out.println("It's a "+ s+" cat and weight "+w+"kg.");
}
}
public class testConstructor1{
public static void main (String args[]){
Cat catA=new Cat("black");
System.out.println("The cat weight" +catA.getWeight()+"kg.");
Cat catB=new Cat("whight",0.9f);
//Cat catc=new Cat();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -