Again, it's hard to answer your question since we don't know what you're trying to do. But I suspect you want to define your classes like this:
If you're just playing around with
Java, then here's a tip: All instance fields, like "x" should be defined as private. Avoid re-defining an instance field in sub-classes because it gets confusing. Since you defined "x" in Fruit it is also automatically part of Apple, so there's no need to redefine it. In my code, there's no way to assign a value to x. There's no single "right way" to do this -- it depends on what "x" represents. You could initialize it as you define it or in Fruit's constructor, and, if you design calls for it, you could have a "setX(int x)" method.