Java MCQs

Java MCQs

Professional Development

10 Qs

quiz-placeholder

Similar activities

Kuis Pemrograman

Kuis Pemrograman

Professional Development

15 Qs

2.13.2022 | Introduction to Java Review

2.13.2022 | Introduction to Java Review

Professional Development

8 Qs

Java Fundamentals

Java Fundamentals

Professional Development

11 Qs

GAGC-Dotnet-SET2

GAGC-Dotnet-SET2

Professional Development

15 Qs

Python Class 1

Python Class 1

Professional Development

15 Qs

Exception Handling-2

Exception Handling-2

Professional Development

10 Qs

PreTrainingExceptions

PreTrainingExceptions

Professional Development

10 Qs

java quizz

java quizz

Professional Development

10 Qs

Java MCQs

Java MCQs

Assessment

Quiz

Computers

Professional Development

Hard

Created by

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

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?