0
0
Javaprogramming~5 mins

Instance methods in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an instance method in Java?
An instance method is a method that belongs to an object of a class. It can access instance variables and requires an object to be called.
Click to reveal answer
beginner
How do you call an instance method in Java?
You call an instance method by using an object of the class followed by a dot and the method name, like <code>objectName.methodName()</code>.
Click to reveal answer
intermediate
Can an instance method access static variables directly?
Yes, an instance method can access static variables directly because static variables belong to the class, not to any specific object.
Click to reveal answer
intermediate
What is the difference between an instance method and a static method?
An instance method requires an object to be called and can access instance variables. A static method belongs to the class itself and can be called without creating an object.
Click to reveal answer
intermediate
Why can't you call an instance method from a static context without an object?
Because instance methods need an object to know which instance's data to work with. Static context has no specific object, so it cannot call instance methods directly.
Click to reveal answer
How do you call an instance method named display on an object car?
Acar.display()
Bdisplay.car()
CCar.display()
Ddisplay()
Which of these is true about instance methods?
AThey cannot access static variables.
BThey can be called without creating an object.
CThey belong to the class, not objects.
DThey can access instance variables.
Can an instance method access static variables?
ANo, only static methods can access static variables.
BYes, instance methods can access static variables.
COnly if the static variable is public.
DOnly if the instance method is static.
What happens if you try to call an instance method from a static method without an object?
AIt works fine.
BIt calls the method on a default object.
CIt causes a compile-time error.
DIt runs but with null values.
Which keyword is used to refer to the current object inside an instance method?
Athis
Bself
Ccurrent
Dobj
Explain what an instance method is and how it differs from a static method.
Think about whether you need an object to call the method.
You got /4 concepts.
    Describe why you cannot call an instance method directly from a static method without an object.
    Consider what 'static' means about belonging to the class.
    You got /3 concepts.