
Java MCQs

Quiz
•
Computers
•
Professional Development
•
Hard
Ms STAFF
Used 2+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following will cause a compile-time error?
class Demo {
static int x = 10;
int y = 5;
static void test() {
System.out.println(y);
}
}
Error due to static method accessing y
No error
Error in variable declaration
Error in class declaration
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of these is true about constructors in Java?
Constructors must have a return type
Constructors can be inherited
Constructors can be overloaded
You must define at least one constructor
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which is the parent class of all classes in Java?
Object
Class
SuperClass
Base
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What happens if you do not provide a constructor in a class?
Compile error
Java provides a default constructor
Object cannot be created
Class won't compile
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output?
public class Demo {
static {
System.out.println("Static block");
}
public static void main(String[] args) {
System.out.println("Main method");
}
}
Main method
Static block
Static block
Main method
Compile error
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which block runs first when a class is loaded?
Constructor
Static block
Main method
Instance block
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What happens if we try to access a non-static variable from a static method?
It compiles and runs normally
Compile-time error
Runtime exception
It automatically converts to static
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
Abstract Class #1

Quiz
•
Professional Development
15 questions
FORMATIVE ASSESSMENT 2 OOPS

Quiz
•
Professional Development
10 questions
PBO

Quiz
•
Professional Development
11 questions
Python: Quiz 1.03 - Code Structure and Workings

Quiz
•
Professional Development
10 questions
Java main() and Scanner

Quiz
•
Professional Development
12 questions
StreamQuiz

Quiz
•
Professional Development
10 questions
Java Strings

Quiz
•
1st Grade - Professio...
10 questions
C++Quiz#1

Quiz
•
Professional Development
Popular Resources on Wayground
50 questions
Trivia 7/25

Quiz
•
12th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
11 questions
Negative Exponents

Quiz
•
7th - 8th Grade
12 questions
Exponent Expressions

Quiz
•
6th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade
20 questions
One Step Equations All Operations

Quiz
•
6th - 7th Grade
18 questions
"A Quilt of a Country"

Quiz
•
9th Grade