Trying to print out the attributes of the object Problem - Java
Hi everyone. Currently, I have one super class called "Animal" which holds the classes "Dog" and "Dog breeds1" and "DogBreed2". I created individual objects within each Dogbreed class and I'm trying to figure out how to print out the attributes of of the objects from these differing classes. The error I get is "<identifer expected>". Any ideas? Still experimenting at the moment. public class Animal { //setting attributes that every Animal will have int legs; //how many legs the animal will have String colour; public class Dog{ //setting the Animal attributes to our dogs Dog.legs = 4; //each and every dog will have 4 legs public class DogBreed1{ //our individual dogs of dogbreed 1 Animal Buddy = new Animal(); Animal Chip = new Animal(); //Buddy will be Brown Animal.Dog.Buddy = "Brown"; } public class DogBreed2{ //our individual dogs of dogbreed 2 Animal Ralph = new Animal(); Animal Buster = new Animal(); } } } public class Pr{ public static void main(String [] args) { System.out.print(Animal.Dog.DogBreed1.Buddy.colour); //print out the colour of buddy System.out.print(Animal.Dog.DogBreed2.Buster.legs); //print out how many legs buster has } }