class static1{Error message:
static int x = count();
int count(){return 10;}
public static void main(String args[]){
static1 static1 = new static1();
System.out.print(static1.count());
}
}
Cannot make a static reference to the non-static method count() from the type static1
Since static methods and variables can’t assess the methods which is not be created, can change modifier of count() to static, so that the static variable referencing a static method ().
Solution :
class static1{
static int x = count();
static int count(){return 10;}
public static void main(String args[]){
static1 static1 = new static1();
System.out.print(static1.count());
}
}
No comments :
Post a Comment