Having 2 variables with the same name in a class that extends another class in Java

后端 未结 4 1966
挽巷
挽巷 2020-12-31 04:29

Following is a part of my code for a project:

public class Body extends Point{
    public double x, y, mass;

    public Body() {
        x = y = mass = 0;
         


        
4条回答
  •  轮回少年
    2020-12-31 05:30

    Further to what others have said: Is Body a Point? No, Body has a position property of type Point. So Body probably should not extend Point. If you get rid of inheritance (of implementation) then you get rid of a lot of problems. That and use private (not protected!) and final liberally.

提交回复
热议问题