
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
11 questions
java 11-10-2023

Quiz
•
Professional Development
11 questions
Java Fundamentals

Quiz
•
Professional Development
10 questions
C++Quiz#1

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 Chapter 1

Quiz
•
Professional Development
10 questions
Java Interface Quiz

Quiz
•
Professional Development
Popular Resources on Wayground
12 questions
Unit Zero lesson 2 cafeteria

Lesson
•
9th - 12th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
20 questions
Lab Safety and Equipment

Quiz
•
8th Grade
13 questions
25-26 Behavior Expectations Matrix

Quiz
•
9th - 12th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
11 questions
All about me

Quiz
•
Professional Development
10 questions
How to Email your Teacher

Quiz
•
Professional Development
5 questions
Setting goals for the year

Quiz
•
Professional Development
14 questions
Disney Trivia

Quiz
•
Professional Development
14 questions
2019 Logos

Quiz
•
Professional Development
7 questions
How to Email your Teacher

Quiz
•
Professional Development
11 questions
NFL Football logos

Quiz
•
KG - Professional Dev...
20 questions
Employability Skills

Quiz
•
Professional Development