1010
This commit is contained in:
		
							parent
							
								
									a3e84dc516
								
							
						
					
					
						commit
						c34ef6f2c2
					
				@ -1,37 +1,37 @@
 | 
				
			|||||||
package chapter3;
 | 
					package chapter3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Student {
 | 
					//class Student {
 | 
				
			||||||
    String name;
 | 
					//    String name;
 | 
				
			||||||
    int age;
 | 
					//    int age;
 | 
				
			||||||
    String sex;
 | 
					//    String sex;
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
    void read() {
 | 
					//    void read() {
 | 
				
			||||||
        System.out.println("大家好,我是" + name + ",我在看书!");
 | 
					//        System.out.println("大家好,我是" + name + ",我在看书!");
 | 
				
			||||||
    }
 | 
					//    }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
    void introduce() {
 | 
					//    void introduce() {
 | 
				
			||||||
        System.out.println("大家好,我叫" + name + ",我今年" + age + "岁了,我是" + sex + "孩");
 | 
					//        System.out.println("大家好,我叫" + name + ",我今年" + age + "岁了,我是" + sex + "孩");
 | 
				
			||||||
    }
 | 
					//    }
 | 
				
			||||||
}
 | 
					//}
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
public class Example01 {
 | 
					//public class Example01 {
 | 
				
			||||||
    public static void main(String[] args) {
 | 
					//    public static void main(String[] args) {
 | 
				
			||||||
        Student s1 = new Student();
 | 
					//        Student s1 = new Student();
 | 
				
			||||||
        Student s2 = new Student();
 | 
					//        Student s2 = new Student();
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
        s1.name = "小明";
 | 
					//        s1.name = "小明";
 | 
				
			||||||
        s1.sex = "男";
 | 
					//        s1.sex = "男";
 | 
				
			||||||
        s1.age = 20;
 | 
					//        s1.age = 20;
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
        s2.name = "小红";
 | 
					//        s2.name = "小红";
 | 
				
			||||||
        s2.sex = "女";
 | 
					//        s2.sex = "女";
 | 
				
			||||||
        s2.age = 19;
 | 
					//        s2.age = 19;
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
        s1.read();
 | 
					//        s1.read();
 | 
				
			||||||
        s2.read();
 | 
					//        s2.read();
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
        s1.introduce();
 | 
					//        s1.introduce();
 | 
				
			||||||
        s2.introduce();
 | 
					//        s2.introduce();
 | 
				
			||||||
    }
 | 
					//    }
 | 
				
			||||||
}
 | 
					//}
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,10 @@ class Book {
 | 
				
			|||||||
//        this.id = 0;
 | 
					//        this.id = 0;
 | 
				
			||||||
//        this.name = "未命名";
 | 
					//        this.name = "未命名";
 | 
				
			||||||
//        System.out.println("初始化:无参构造被调用!");
 | 
					//        System.out.println("初始化:无参构造被调用!");
 | 
				
			||||||
 | 
					//    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//    public Book(int id, String name) {
 | 
				
			||||||
 | 
					//        this.id = id;
 | 
				
			||||||
//    }
 | 
					//    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // 打印信息
 | 
					    // 打印信息
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										22
									
								
								src/chapter3/Example09.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/chapter3/Example09.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					package chapter3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Student {
 | 
				
			||||||
 | 
					    private String name;
 | 
				
			||||||
 | 
					    private int age;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Student(String name, int age) {
 | 
				
			||||||
 | 
					        name = name;
 | 
				
			||||||
 | 
					        age = age;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void read() {
 | 
				
			||||||
 | 
					        System.out.println("我是" + name + ",我今年" + age + "岁");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Example09 {
 | 
				
			||||||
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
					        Student stu = new Student("小明", 15);
 | 
				
			||||||
 | 
					        stu.read();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user