Java From Beginner To Advanced

0% completed

Previous
Next
Quiz
Question 1
What is the scope of a local variable defined inside a method in Java?
A
Accessible throughout the class
B
Accessible only within the method where it is defined
C
Accessible within the same package
D
Accessible to all subclasses
Question 2
What will be the output of the following Java code?
public class Solution {
    public static void main(String[] args) {
        int number = 10;
        display();
        System.out.println("Number: " + number);
    }
    
    public static void display() {
        // System.out.println("Number inside display: " + number);
    }
}
A
Number inside display: 10
B
Compilation Error
C
No output
D
Number: 10
Question 3
What is the default return type of a method in Java if no return type is specified?
A
int
B
void
C
Compilation Error
D
Object

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next