116k views
5 votes
Here is a Test Code segment:

public class MyTesterClass
{
public static void main(String[] args)
{
MyClass myObject = new MyClass (12.4, 20);

int value1 = MyClass.SOME_VALUE;
int value2 = myObject.method1();
int value3 = MyClass.method2(20);
}
}

I'm trying to figure out what part of this code is a "CLASS METHOD" and I'm tempted to guess it's method2... It could also be MyClass, SOME_VALUE, or method1 I believe. I'm not the best with coding classifications and would like some help.

1 Answer

4 votes
Here's the best answer I can give you, but bear with me.
The second option is incorrect because a class method must have a class identifier not an object identifier. What makes myObject an object identifier is the fact that it was created as an instance of the class MyClass in the constructor in line 5 (MyClass myObject= new MyClass(12.4,20);
The answer here should be MyClass.method2(20); Methods must have a set of parentheses, even if it has nothing inside. The first answer has a class identifier but the SOME_VALUE acts much like the Integer.MAX_VALUE; code which stores a constant value and does not actually perform tasks like most methods.
In short, the answer should be the last one but I hope my explanation cleared some things up for you, even if it was a bit more concept heavy than the question probably intended.
User MiguelB
by
7.8k points