1Z0-811 Java Methods and Scope Flashcards
6 cards from real 1Z0-811 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 1Z0-811 Java Methods and Scope flashcards as text
What is the purpose of the `this` keyword inside an instance method?
Answer: It refers to the current object instance
The `this` keyword refers to the current instance of the class and is used to access its fields and methods.
Which access modifier restricts a method's visibility to the same class only?
Answer: private
The `private` access modifier makes a method accessible only within the class in which it is declared.
Can a `static` method access instance variables directly?
Answer: No, because static methods belong to the class, not an instance
Static methods do not have access to instance variables directly because they are not associated with any object instance.
Which of the following is true about variable shadowing in Java?
Answer: It occurs when a local variable has the same name as an instance variable
Variable shadowing occurs when a local variable or parameter has the same name as an instance variable, hiding the instance variable within that scope.
What is the difference between pass-by-value and pass-by-reference in the context of Java method arguments?
Answer: Java uses pass-by-value; for objects, the reference value (address) is passed
Java always passes arguments by value; for object types, the value passed is the reference (memory address) of the object, not the object itself.
Which of the following correctly declares a varargs parameter in a method?
Answer: public void print(String... args)
Varargs is declared using an ellipsis (`...`) after the type, allowing a method to accept zero or more arguments of that type.