testconstructor1.java

来自「JAVA的例子程序」· Java 代码 · 共 27 行

JAVA
27
字号
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 + =
减小字号Ctrl + -
显示快捷键?