Implement a final class without the “final” keyword

后端 未结 7 1704
生来不讨喜
生来不讨喜 2020-12-29 10:53

A friend of mine was asked that question in his on-phone job interview a couple of days a go. I don\'t have a clue. can anyone suggest a solution? (His job interview is ov

7条回答
  •  时光取名叫无心
    2020-12-29 11:03

    public class Immutable {       
        private int val;
    
        public Immutable(int v)
        { 
            this.val = v;
        }
    
        public int getVal() { return this.val; }
    }
    

提交回复
热议问题