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 method chaining in Java?
Answer: Calling multiple methods sequentially on the same object by returning `this`
Method chaining allows multiple method calls to be linked on the same object when each method returns `this` or another object.
Which of the following method signatures would cause a compilation error due to ambiguity in overloading?
Answer: void test(int a) and int test(int a)
Two methods with the same name and parameter list but different return types are not valid overloads and cause a compilation error.
What does it mean for a method to be `final`?
Answer: It cannot be overridden in a subclass
A `final` method cannot be overridden by subclasses, ensuring its behavior remains unchanged in the inheritance hierarchy.
In Java, where can a local variable be declared?
Answer: Anywhere inside a block where it is needed
Local variables in Java can be declared anywhere inside a block, but they must be initialized before use.
Which statement about abstract methods is correct?
Answer: Abstract methods have no body and must be implemented by concrete subclasses
An abstract method has no implementation body and requires any concrete (non-abstract) subclass to provide its implementation.
What is the correct way to call a static method `calculate` from the same class `MathUtil`?
Answer: MathUtil.calculate() or just calculate() within the class
Static methods are called on the class name (e.g., `MathUtil.calculate()`) or simply by method name within the same class without an object reference.