Objects and classes

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


then we can invoke the constructor in the main function.

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??


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


me too
I got that fortunatly


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


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