尚学堂java 答案解析 第四章

本答案为本人个人编辑,仅供参考,如果读者发现,请私信本人或在下方评论,提醒本人修改
一.选择题
1.BD
解析:B:类必须有构造方法,若程序未写,这系统自动调用系统构造方法.
D:super()会调用父类的构造方法,但父类的构造方法不一定无参
2.D
解析:3+4=7
3.AC
解析:A:静态方法在类被加载进内存时就分配入口地址,此时不一定有非静态方法
D:this表示构造方法创建的对象,在该类被调用时候才产生,而静态方法在加载内存时候就存在,此时不存在对象,不能用this调用.
4.AC
解析:A 理由同上 C:只要权限够,可以调用其他类的方法
5.C
解析:count是全局变量,count1()方法覆盖后为10; 如果count1中的count1前加int,使count1()中的count成为局部变量,则为B
二.简答题
1.面向过程是将任务分步,一步一步实现.面向对象是将任务分块拆分,每块再用面向过程实现.
2.类是对象的抽象集合,对象是类的具体个体.
【尚学堂java 答案解析 第四章】3.作用:初始化对象
特征:必须与类名相同,且没有类型
4.作用:代表正在调用该方法的对象
用法:this.成员变量
5.作用:为了共享变量或方法
三.编码题
1.

public class People { private String name; private int age; People(String name,int age){ this.name = name; this.age = age; } void display(){ System.out.println("姓名:"+name); System.out.println("年龄:"+age); } } classch4_1{ public static void main(String[] args) { People tom = new People("tom",18); tom.display(); } }

2.
public class Circle { finalfloat PI = 3.14f; float r = 0.0f; voidgetArea(float r){ this.r = r; System.out.println("面积:"+PI*this.r*this.r); } void getPerimeter(float f){ this.r = r; System.out.println("周长:"+PI*this.r*2); } } classTest{ public static void main(String[] args) { Circle r = new Circle(); r.getArea(3); r.getPerimeter(3); } }

3.
public class User { String id = ""; String pwd = ""; String email = ""; User(String id ,String pwd ,String email){ this.id = id; this.pwd = pwd; this.email = email; } User(String id){ this.email = id + "@gameSchool.com"; System.out.println("email:"+this.email); }} classCh4_3{ public static void main(String[] args) { User user = new User("tom"); } }


    推荐阅读