面向对象
1.三大特性:封装、继承、多态
2.值传递、引用传递
引用传递:其实也是值传递,只不过该值为对象的地址值
package com.oop;
public class DemoTwo {
public static void main(String[] args) {
//引用传递:对象,本质还是值传递,但是该值为对象的地址值
Student student = new Student();
System.out.println(student.name);//null
DemoTwo.change(student);
System.out.println(student.name);//zhangsan
}
public static void change(Student student){
student.name = "zhangsan";
}
}
//定义一个Student类
class Student{
String name;
}
3.this指针
package com.oop.DemoTwo;
public class Student {
//属性:字段
String name;
int age;
//方法
public void study(){
System.out.println(this.name+"在学习");
}
}
package com.oop.DemoTwo;
//一个项目应该只存在一个main方法
public class Application {
public static void main(String[] args) {
//类:抽象的
// 类实例化后会返回一个自己的对象
Student student = new Student();
System.out.println(student.name);//null
System.out.println(student.age);//0
student.name = "zhangsan";
student.age = 10;
System.out.println(student.name);//zhangsan
System.out.println(student.age);//10
student.study();//zhangsan在学习
student.name = "lisi";
student.study();//lisi在学习
}
}