标签:style blog color 使用 java ar div sp 代码
1 public class Dog { 2 //颜色 3 String color; 4 //名称 5 String name; 6 //体重 7 int weight; 8 9 public Dog(){} 10 public Dog(String color,String name,int weight){ 11 this.color = color; 12 this.name = name; 13 this.weight = weight; 14 } 15 16 public String getColor(){ 17 return color; 18 } 19 public void setColor(String color){ 20 this.color = color; 21 } 22 23 public static void main(String[] args) { 24 25 Dog dog = new Dog(); 26 dog.setColor("red"); 27 28 System.out.println( dog.getColor()); //red 29 } 30 }
this.color = color;this.name = name;
this.color = color;// this.name = name;this(name);
// this.color = color;//this.name = name;//这两行代码可以使用这一句来代替this(color,name);this.weight = weight;
修饰符
|
类内部
|
同一个包
|
子类 |
任何地方
|
public
|
√ |
√
|
√
|
√
|
protected
|
√
|
√
|
√
|
|
default
|
√
|
√
|
|
|
private
|
√
|
|
|
|
标签:style blog color 使用 java ar div sp 代码
原文地址:http://www.cnblogs.com/Essence/p/3963352.html