Access a private variable from the superclass (JAVA)

后端 未结 6 2074
终归单人心
终归单人心 2021-02-08 20:19

Ok so I have studied java all semester and thought I had a clear understanding about inheritance and super/sub classes. Today we were given as assignment for making a superclass

6条回答
  •  醉梦人生
    2021-02-08 21:20

    Those are just the constraints of the assignment, not Java itself. You could give the superclass protected data members, and then access those directly from the subclass. However, the professor likely wishes to teach you about how a superclass can protect its data members from direct access by a subclass, and protected methods would be a way to do that.

提交回复
热议问题