Java: static field in abstract class

后端 未结 8 1066
独厮守ぢ
独厮守ぢ 2020-12-24 01:04

I just start out with an example, that explains it best:

public abstract class A{
    static String str;
}

public class B extends A{
    public B(){
                


        
8条回答
  •  醉梦人生
    2020-12-24 01:32

    only one instance of static variable is present in the system.

    static variable will load into the system in the start before class is loaded.

    reason both time abc is printed is because you set the value of str as abc in the last.

提交回复
热议问题