package com.leo.superDemo;
public class A {
public int n1 = 100;
protected int n2 = 200;
int n3 = 300;
private int n4 = 400;
// 父类无参构造器
public A() {
System.out.prinln("A()");
}
// 父类带参构造器
public A(String name) {
System.out.println("A(String name)");
}
public void test100() {
}
protected void test200() {
}
void test300() {
}
private void test400() {
}
}
package com.leo.superDemo;
public class B extends A{
// 调用父类构造器
public B() {
// super();
super("java");
}
// 访问父类的属性,但不能访问父类的private属性
public void hi() {
System.out.println(super.n1 + super.n2 + super.n3); // 不能访问n4
}
// 访问父类的方法,但不能访问父类的private方法
private void ok() {
super.test100();
super.test100();
super.test300();
// super.test400() 不能访问
}
}