Objects and classes


#1
class Dog {
  
  int age;

	public Dog() {
  
  }


	public static void main(String[] args) {

	}

}

why does public static void main(String[] args) come after the constructor was made


#2

then we can invoke the constructor in the main function.


#3
class Dog {
 int age;
public Dog(int dogsAge){
age = dogsAge;
}
public static void main(String[] args){
 Dog spike = new Dog(12);
}
}

I did this programm in code academy here its working but in netbeans last line have error
non static variable this can not be referenced from a static context
what is the problem??


#4

i ran the code:

no problems what so ever, how did you create the package? in my case i created a Dog application, which would be the way to go


#5

me too
I got that fortunatly


#6

but you said you got an error in netbeans? I ran your code in netbeans, and its fine. If you need further help, please ensure i can replicate the problem


#7

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