private
private
没有对象的都是垃圾!
a'a'a
public String getName(){
}
成员变量:new出来 定义在类
局部变量:调用方法的时候
内部类重名Outer.this.name
内部类可以访问外部类的成员,外部类可以
final 修饰变量、类、方法:
1 变量无法被修改
2 类无法被继承
3 方法无法别重写
不能重写private方法(私有)
优点:1减少代码量2代码变得简洁3代码更加容易维护变得
单继承,不是多继承(很好)
就近原则(同名时):
控制 this.name,super.name
调用父类的构造方法:
super() 无参构造方法
super(name, age,gender,birthday)
getter setter
封装、继承、
this 指针 只能在类里使用 代表当前对象
private 只能在类的内部使用
局部变量 成员变量
栈 堆
存储
回收机
class ..{
public static void main(String[] args){
}
}
class Student{
String name;
}
没有定义构造方法时默认构造方法:起到一个初始化的
public name(){
}
System.out.println("open");
System.out.println("take");
System.out.println("close");
class BingXiang{
int capacity;
Stirng brand;
String model;
String content;
public void open(){
System.out.println("open the icebox")
}
public void close(){
System.out.println("close the icebox")
}
public void put(String name){
content = name;
}
}
BinXiang bc = new BingXiang();
bc.open();
bc.put("daxiang");
bc.close();
class Demo{
public static void main(String[] args){
Plane p1 = new Plane();
Syetem.out,println(p1.model);
System.out.println(p1.length);
System.out.println(p1.zaiKeLiang);
Plane p2 = new Plane();
Syetem.out,println(p1.model);
System.out.println(p1.length);
System.out.println(p1.zaiKeLiang);
}
}
class Plane{
Stirng model;
float length;
int zaiKeliang;
}
老师