Classes: Instance Variables


#1



Object-Oriented Java Classes: Instance Variables

Question : Let's model the Dog class after a real-world dog. Create an int instance variable called age.


I don't know why I'm getting errors in code they keep saying
Did you create an instance variable called age? Place it inside of the class, but before the Dog constructor. and I did but it says it wrong can someone please explain whats wrong with my code


class Dog {   
	public static void main(String[] args) {
  int age;
    public Dog() {

  		
  		}
	 }
}


#2

Just move the main method outside the Dog constructor and it should be fine.


#3

it worked thank you for the help
class Dog {
int age;
public Dog() {}
public static void main(String[] args) {}

}


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.