- public class Main {
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- Computer ye = new Computer();
-
- ye.kb = new Keyboard();
- ye.ms = new Mouse();
- ye.sc = new Screen();
- ye.cpu = new Host();
- ye.ram = new Host();
- ye.disk = new Host();
-
- ye.showProfile();
- }
- }
複製代碼- public class Computer {
- Keyboard kb = new Keyboard();
- Mouse ms = new Mouse();
- Host cpu = new Host();
- Host ram = new Host();
- Host disk = new Host();
- Screen sc = new Screen();
- void showProfile()
- {
- System.out.println(kb.keys);
- System.out.println(ms.length);
- System.out.println(cpu.frequency);
- System.out.println(ram.speed);
- System.out.println(disk.capacity);
- System.out.println(sc.resolution);
- }
-
- }
複製代碼- public class Host {
- int frequency, speed, capacity;
-
- Host()
- {
- frequency =100;
- }
-
-
-
- }
複製代碼- public class Keyboard {
- int keys;
-
- Keyboard()
- {
- keys = 70;
- }
-
- Keyboard(int keys)
- {
- this.keys = keys;
- }
- }
複製代碼- public class Mouse {
- int length;
-
- Mouse()
- {
- length = 100;
- }
-
- Mouse(int length)
- {
- this.length = length;
- }
- }
複製代碼- public class Screen {
- int resolution;
-
- Screen()
- {
- resolution = 300;
- }
-
- Screen(int resolution)
- {
- this.resolution = resolution;
- }
- }
複製代碼 |