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
Which keyword is used to define a method that belongs to the class rather than an instance?
Answer: static
The `static` keyword declares a method that belongs to the class itself and can be called without creating an instance.
What is the return type of a method that does not return any value?
Answer: void
A method declared with `void` as its return type does not return any value to the caller.
Which of the following correctly defines method overloading in Java?
Answer: Multiple methods in the same class share the same name but have different parameter lists
Method overloading occurs when multiple methods in the same class have the same name but differ in the number or types of parameters.
What is the scope of a variable declared inside a method body?
Answer: Local scope
A variable declared inside a method has local scope and is accessible only within that method.
Which statement about the `return` statement is true?
Answer: It immediately exits the method and optionally returns a value
The `return` statement immediately terminates method execution and can pass a value back to the caller if the method is non-void.
What happens if a method declares a return type but has a code path that does not return a value?
Answer: The code will not compile
Java requires that all code paths in a non-void method return a value; missing return paths cause a compilation error.