访问权限的区别:
public;
同一工程下的类可以任意访问
protected;
同一工程的同一包可以任意访问、不同包的子类可以访问
default;
同一工程的同一包可以任意访问
private;
只有自己的类可以访问
this super;
this:
当前类的对象
public class Test extends Student{
public Test(){
this(10);
System.out.println("子类构造函数");
}
super:
表示父的对象
public class Test extends Student{
public void play(){
super.play();
System.out.println("子类学生玩");
}
final;
凡是被final标记的,一略不再被重写、赋值。
static:需要最先定义类的静态属性,再者定义方法的静态属性,并且方法只执行一次
。
输入代码:
public class Teacher {
public static int age = 10;
static{
age++;
System.out.println("北风吹");
}
{
age++;
System.out.println("秋风凉");
}
public Teacher(){
age++;
System.out.println("谁家娇妻守空房");
}
public static void teach(){
age++;
System.out.println("你有困难我帮忙");
}
public void play(){
age++;
System.out.println("我住隔壁我姓王");
}
}
执行结果:
北风吹
秋风凉
谁家娇妻守空房
秋风凉
谁家娇妻守空房
你有困难我帮忙
你有困难我帮忙
你有困难我帮忙
我住隔壁我姓王
我住隔壁我姓王
break、continue、return的区别:
public class Test {
public static void main(String[] args){
for(int i = 0;i<10;i++){
System.out.println("第一层循环:"+i);
for(int j=0;j<10;j++){
System.out.println("第二层循环"+j);
}
}
}
(代码已试,结果过长,不发表)
break;
跳出当前(循环的这一层) 循环
continue;
结束所有循环
return;
跳过当前循环,执行下一循环