Day06_Java_作业
来源:互联网 发布:网络爬虫是干嘛的 编辑:程序博客网 时间:2024/06/15 07:07
A:简答题
1. 类是什么? 对象是什么?举例说明
2. 类由哪些内容组成?
3. 成员变量与局部变量的区别?
4. 什么是匿名对象?什么时候使用匿名对象?
5. 使用面向对象【封装】的好处有哪些?
6. private关键字在哪里使用? 被private修饰的成员有什么特点?
7. 为什么要有this关键字?this关键字的含义?
8. 面向对象语言的特征有那些?
B:看程序写结果(写出自己的分析理由),程序填空,改错,看程序写结果。
1、写出这个输出的结果
class Test {
int num = 3;public static void main(String[] args) { Test t = new Test(); t.num = 5; method(t); System.out.println(t.num);}public static void method(Test t){ t.num = 6;}
}
答:6
2、写出这个输出的结果
class Test {
int num = 3;public static void main(String[] args) { Test t = new Test(); t.num = 5; method(new Test()); System.out.println(t.num);}public static void method(Test t){ t.num = 6;}
}
答:5
C:编程题
1、通过面向对象的思想,描述你自己的电脑类.并且使用这个类.
(要求包含成员变量、成员方法)
答:
电脑类
package student;/** * @author Aoman_Hao */public class Day7_computer { String name; int price; public void show(String name,int price){ System.out.println("手机品牌:"+name); System.out.println("手机价格:"+price); } }
测试类:
package student;import java.util.Scanner;/** * @author Aoman_Hao */public class Day7_computerTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入电脑品牌:"); String name = sc.nextLine(); System.out.println("请输入电脑价格:"); int price = sc.nextInt(); Day7_computer computer = new Day7_computer(); computer.show(name, price); }}