Instance Methods MCQ
What is an instance method in Java?
A. A method that belongs to the class rather than an object
B. A method that can only be called from a static context
C. A method that belongs to an instance of a class
D. A method that must be declared as final
How can you call an instance method in Java?
A. Using the class name
B. Using an object reference
C. Using the this keyword within a static method
D. Using the super keyword
Which of the following is true about instance methods?
A. They can be called without creating an instance of the class
B. They can access instance variables and other instance methods directly
C. They must be declared as static
D. They can only access static variables
What is required to invoke an instance method from another instance method?
A. A reference to the class
B. A reference to the object
C. A reference to the method's name
D. A reference to the package
Can instance methods be overloaded in Java?
A. Yes
B. No
C. Only if they are final
D. Only if they are static
Which of the following statements is true regarding instance methods?
A. They are implicitly static
B. They cannot be overridden in subclasses
C. They can access the current object's state
D. They can only be accessed through the class name
What is the access level of an instance method if no access modifier is specified?
A. public
B. protected
C. private
D. package-private (default)
How are instance methods defined in a Java class?
A. With the static keyword
B. With the instance keyword
C. Without the static keyword
D. With the abstract keyword
Can instance methods be abstract?
A. Yes, but they must be implemented in a subclass
B. No, instance methods cannot be abstract
C. Yes, and they must be implemented in the same class
D. No, only static methods can be abstract
What keyword can be used inside an instance method to refer to the current object?
A. super
B. this
C. self
D. current
Can an instance method access static variables?
A. No
B. Yes, but only if they are private
C. Yes, directly without any restrictions
D. Yes, but only through an object reference
Which of the following is not allowed in an instance method?
A. Accessing instance variables
B. Calling other instance methods
C. Accessing static methods
D. Accessing private variables of other objects
What is the scope of an instance method?
A. Within the method where it is declared
B. Within the class, including subclasses
C. Across all instances of the class
D. Within the object for which it was called
Can instance methods be synchronized?
A. No, only static methods can be synchronized
B. Yes, to control access from multiple threads
C. Yes, but only if they are final
D. No, synchronization is only for instance variables
What is the default return type of an instance method if none is specified?
A. void
B. int
C. Object
D. There is no default; it must be explicitly defined
Which of the following is true about the invocation of instance methods?
A. They are invoked at compile time
B. They can be invoked even if the object is null
C. They are invoked at runtime using the actual object's class
D. They can only be invoked from within the same class
Can instance methods be final in Java?
A. Yes, and they cannot be overridden in subclasses
B. No, only static methods can be final
C. Yes, but they can still be overridden
D. No, instance methods cannot be final
What happens if an instance method tries to modify a final instance variable?
A. The method will modify the variable successfully
B. It will result in a compile-time error
C. It will result in a runtime error
D. It will modify the variable at runtime
Which of the following statements about instance methods and static methods is correct?
A. Both can access instance variables directly
B. Instance methods can access static methods and variables, but not vice versa
C. Static methods can access instance variables directly
D. Instance methods cannot access static methods
How does method overriding relate to instance methods?
A. Only static methods can be overridden
B. Instance methods can be overridden in subclasses
C. Overriding is not possible in Java
D. Instance methods cannot be overridden, only hidden
Answers:
C. A method that belongs to an instance of a class
B. Using an object reference
B. They can access instance variables and other instance methods directly
B. A reference to the object
A. Yes
C. They can access the current object's state
D. package-private (default)
C. Without the static keyword
A. Yes, but they must be implemented in a subclass
B. this
C. Yes, directly without any restrictions
D. Accessing private variables of other objects
D. Within the object for which it was called
B. Yes, to control access from multiple threads
D. There is no default; it must be explicitly defined
C. They are invoked at runtime using the actual object's class
A. Yes, and they cannot be overridden in subclasses
B. It will result in a compile-time error
B. Instance methods can access static methods and variables, but not vice versa
B. Instance methods can be overridden in subclasses
No comments:
Post a Comment