Encapsulation_OOexample-5
作者:互联网
package dataEncapsulation;
public class CatMain
{
public static void main(String[] args)
{
CatNew cat1 = new CatNew("Catty", "red", 4);
// System.out.println(cat1.name);
String colour = cat1.getCoulur();
System.out.println(colour);
cat1.eat();
}
}
package dataEncapsulation;
public class CatNew
{
private String name;
private String colour;
private int age;
// String name;
// String colour;
// int age;
public CatNew(String name, String colour, int age)// 注意public后面不能加void
{
this.name = name;
this.colour = colour;
this.age = age;
}
public String getCoulur()
{
return colour;
}
public void eat()
{
System.out.println("yumy!");
}
}
标签:CatNew,OOexample,String,colour,age,Encapsulation,public,name 来源: https://blog.csdn.net/weixin_45852947/article/details/114891652