Java: static field in abstract class

后端 未结 8 1126
独厮守ぢ
独厮守ぢ 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:24

    I think one way to approach this is to use a singleton for class B and C to mimic static methods and fields. The can both extend abstract class A, but will have their own values of str..

提交回复
热议问题