您的位置:首页 > 编程语言 > Java开发

java,method,contructor,class,属性 程序

2016-07-07 19:28 483 查看
public class Mobile {//class
public String brand;//属性      public是修饰符
public int weight;//属性
public  String getBrand (){//method 方法 String 是返回值类型,一般方法 和构造方法的不同之处。
return brand;
}
public Mobile(String brand,int weight){//constructor 构造方法
this.brand = brand;
this.weight = weight;
}
public static void main(String[] args)//main method,程序入口
{
//Mobile mobile = new Mobile();//无参构造器
Mobile mobile = new Mobile("samsumg",200);//有参数的对象创建。构造器
System.out.println("手机品牌"+mobile.getBrand());
System.out.println(mobile.brand);//对象方法和对象属性的访问用 点 操作符
System.out.println(mobile.weight);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: