2020.7.18第十三天

1.学习了static关键字

静态变量,静态方法以及静态模块

1 public class VarDemo {
2 private static int x=1;
3 public static void main(String[] args){
4 VarDemo.x++;
5 VarDemo v=new VarDemo();
6 v.x++;
7 System.out.println("x="+x);
8 }
9 }
 1 public class StaticBlockDemo {
 2 static (
 3 System.out.println ("静态代码块") ;
 4 }
 5 public StaticBlockDemo() {
 6 System.out.println ("构造方法") ;
 7 }
 8 public static void main(String[] args) {
 9 StaticBlockDemo d=new StaticBlockDemo () ;
10 StaticBlockDemo d2=new StaticBlockDemo () ;
11 }
12 }

final关键字

1 public class FinalVarDemo {
2 private static final int x=5;
3 public static void main(String[] args) {
4 x=10;
5 }
6 }
1 class A{
2 public final void t() {
3 System.out.println("A t()");
4 class B extende A{
5 public void t() (
6 System.out.println("B t()") ;
7 }
8 }
1 final class A{
2 public final void t () (
3 System. out.println("A t()");
4 }
5 }
6 class B extends A{
7 }

final修饰的属性、方法和类均不能被重写

abstract关键字

抽象类

abstract class 类名 {}
public abstract class Type {
}

使用抽象方法必须使用抽象类的子类来实现

必要时还要重写

 

 2.遇到的问题:小学期报告还在整理

3.明天复习第五章

posted @ 2020-07-18 19:36  敲敲代代码码  阅读(108)  评论(0编辑  收藏  举报