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!");
}
}