1. 类和对象的内存处理方式

1.1 方法区(method area)

1.2 堆(heap)

1.3 栈(stack)

2. 对象作为方法的参数和返回值

    public void fun(Scanner scan){
        int i = scan.nextInt();
        System.out.println(i);
    }   
    public Student getStu(){
        Student stu = new Student();
        stu.setName("XiaoMing");
        stu.setAge(11);
        return stu;
    }

3. 成员变量和局部变量

3.1 基本特征

3.2 内存管理

3.3 生命周期

3.4 this关键字的使用

4. private型变量的访问

5. 构造方法

    public class Student {
    public Student (){
        System.out.println("I'm a student");
    };
}
    public class Student {
    public Student (){
        System.out.println("I'm a student");
    };
    public Student(String name,int age){
        System.out.println("My name is"+name+", I'm "+age+"years old");
    }
}
    public class Student {
    public Student (){
       this("java",18) ;//无参构造方法中调用有参构造方法
        System.out.println("I'm a student");
    };
    public Student(String name,int age){
        System.out.println("My name is "+name+", I'm "+age+" years old");
    }
    /*输出结果:
    My name is java, I'm 18 years old
    I'm a student
    */
}

发表回复