1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
package 面向对象;
public class TestFirstClass { int id; int age; String name; Subjects subject; void study() { System.out.println("学习"+subject.name); } void show() { System.out.println("ID:"+this.id); System.out.println("AGE:"+this.age); System.out.println("NAME:"+this.name); } TestFirstClass(){ } public static void main(String[] args) { TestFirstClass stu = new TestFirstClass(); Subjects sub = new Subjects(); sub.name = "JAVA课设"; stu.id = 12345; stu.age = 20; stu.name = "葛宇"; stu.subject = sub; stu.study(); stu.show(); System.out.println(sub); System.out.println(stu.subject); } }
class Subjects{ String name; }
|