第八章
属性的访问控制权限一般为private。( )
答案:对
可以使用构造方法给对象属性赋初值。( )
答案:对
下面程序编译正确。( )下面程序编译错误。( )
答案:对
下面程序显示结果。public class Test{ public static void main(String [] args){ Student zhangsan = new Student("张三", 19, 87); Student lisi = zhangsan; lisi.display(); }}public class Student{ private String name; private int age; private double grade; public Student(String name, int age, double grade){ this.name = name; this.age = age; this.grade = grade; } public void display(){ System.out.println("姓名:" + name); }}
姓名:李四
姓名:张三
姓名:null补全MobIEPhone类的构造方法public class Test{ public static void main(String [] args){ MobilePhone phone1 = new MobilePhone(“HW”,“13000000000”) phone1.display(); }}class MobilePhone{ private String brand; private String code; public MobilePhone(String brand, String code){ } public void display(){ System.out.println("Brand=" + brand); System.out.println("Code=" + code); }}
this.brand = brand; this.code = code;
brand = this.brand; code = this.code;

温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!
点赞(0) dxwkbang
返回
顶部