Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Lewis Evans   on May 05 In Java Category.

  
Question Answered By: Gustavo Taylor   on May 05

It sounds as though you are calling a method from
your main() that is not declared as static.1)
Try adding the "static" keyword to the method,
or2) Move the method call to the
constructor:public class  MyClass { public int x; MyClass()
{ this.x = methodCall();
System.out.println("int value = " + this.x); } public int
methodCall() { //not static! return 2; //return an int
} public static void main(String [] s) {
MyClass mc = new MyClass();
}}HTHepenakPS you wrote "hope all of you get up on the
right
side of the bed this time."1) Sometimes we
beat up on people in a random way just to keep
everybody on their toes!2) The folks here are surly,
unruly and unpredictable!3) We always get up on the
wrong side of bed!:-)

Share: 

 

This Question has 9 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on passing variables Or get search suggestion and latest updates.


Tagged: