Java MCQs

Java MCQs

Professional Development

10 Qs

quiz-placeholder

Similar activities

Pruebas de Software

Pruebas de Software

10th Grade - Professional Development

10 Qs

Code X Trade

Code X Trade

Professional Development

15 Qs

Mech 3

Mech 3

Professional Development

10 Qs

Topic Quiz-1 : Python Basics

Topic Quiz-1 : Python Basics

Professional Development

10 Qs

Quiz constructeurs Java

Quiz constructeurs Java

Professional Development

13 Qs

JS

JS

Professional Development

15 Qs

JavaScript Quiz

JavaScript Quiz

Professional Development

10 Qs

Computer Networks-Model Exam-II-PART-B

Computer Networks-Model Exam-II-PART-B

Professional Development

15 Qs

Java MCQs

Java MCQs

Assessment

Quiz

Computers

Professional Development

Practice Problem

Hard

Created by

Ms STAFF

Used 2+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

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

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?