Inheritance For Variables

0 Developer John · September 23, 2014
Ok, before I show you my code, remember, I don't know how to inherit variables. I don't know if it is different from inheriting strings or not. With that being stated, here is my main class called Tuna:
package me.wizard7611.Inheritance;

public class Tuna{
    public static void main(String[] args){
        Apples appleObject = new Apples();
    //System.out.println(cookie); gives me an error saying "Cookie cannot be resolved as a variable"


My subclass:
package me.wizard7611.Inheritance;

public class Apples {
    private void food(){
        int cookie = 4;


Why exactly do I get the error and how can I solve it? 


Post a Reply


- page 2
Oldest  Newest  Rating
0 Developer John · September 24, 2014
@Koen Prins No, what you do is create an object for the Apple class. The objects name is grannySmith. I still don't understand what this means:
new Apple();

1. How do you use it properly?
2. Is it a substitute for:
Apple appleObject = new Apple();
0 Developer John · September 25, 2014
Thank you for organizing all that up.8-)
  • 1
  • 2

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator