Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by using this.
answer is C. :D
finally i tested..we can invoke static method even it is not in the object.
a constructor's main role is initializing its object.but we also can invoke static methods from the template..
ehm ... static doesn't mean it's not in the object.
it just means it has the same value/behaviour for each and every instance of the class, while for instance methods the result of (for instance) a get-method will return the value linked to that instance of the class.
yes, they are shared through all instances, and if you have a static variable in that class, setting the value for one instance will set it for each instance of this class, so far I agree.
but, the static variables and methods are in the object itself, the values are just not depending on the instance, but on the class they're stored in.
so, for instance, you can create an instance var of a class, which has a static printMe() method, and you can call it as
Wehn in doubt check the official documentation. Here's what the JLS says:
126.96.36.199 static Fields
If a field is declared static, there exists exactly one incarnation of the field, no
matter how many instances (possibly zero) of the class may eventually be created.
A static field, sometimes called a class variable, is incarnated when the class is
This makes it clear that static fields cannot be in any object that is an instance of the class. They are associated with the class itself. So although stultuske's explanation correctly describes the end result, Samith Dilhara's version is closer to the JLS.
when you call var.method() from a reference variable,it doesn't mean the static method is in the same object.Static members are belongs to the class's blueprint(template).actually it is an object that is created by the JVM when you RUN your application. var.method() check the object's methods and if it is not in that object, points to the class Object(template) and finds the method.CLASSNAME.member is the best way to invoke static members.