Core Java Quiz - Quiz Questions - 22 May, 2023



Title: Core Java Quiz

Reading Time: 3 Minutes

Published Time: 22 May, 2023



1. Which of the below is valid way to instantiate an array in java?

 

A. int myArray [] = {1, 3, 5};

B. int myArray [] [] = {1,2,3,4};

C. int [] myArray = (5, 4, 3);

D. int [] myArray = {“1”, “2”, “3”};



 

2. Which of the below are reserved keyword in Java?

 

A. array

B. goto

C. null

D. int




 

3. What will happen if we try to compile and run below program?

 

interface Foo{ int x = 10;}

 

public class Test {

    public static void main(String[] args) {

        Foo.x = 20;

        System.out.println(Foo.x);

    }

}

A. Prints 10

B. Prints 20

C. Compile Time Error

D. Runtime error because Foo.x is final.




 

4. What will be the output of the below program?

 

public class Test {

  public static void main(String[] args) {

    char c = 65;

    System.out.println("c = " + c);

  }

}

A. Compile Time Error

B. Prints “c = A”

C. Runtime Error

D. Prints “c = 65”




 

5. What will be output of below program?

 

public class Test {

    public void main(String[] args) {

        int x = 10*20-20;

        System.out.println(x);

    }

}

A. Runtime Error

B. Prints 180

C. Prints 0

D. Compile-time error.





 

6. What are the valid statements for static keyword in Java?

 

A. We can have static block in a class.

B. The static block in a class is executed every time an object of class is created.

C. We can have static method implementations in interface.

D. We can define static block inside a method.




 

7. Select all the core concepts of OOPS.

 

A. Abstraction

B. Inheritance

C. Interface

D. Polymorphism

E. Generics














 

8. Which of the following statements are true for inheritance in Java?

 

A. The “extend” keyword is used to extend a class in java.

B. You can extend multiple classes in java.

C. Private members of the superclass are accessible to the subclass.

D. We can’t extend Final classes in java.




 

9. What will be the output of below program?

 

package com.journaldev.java;

 

public class Test {

  public static void main(String[] args) {

    Super s = new Subclass();

    s.foo();

  }

}

 

class Super {

  void foo() {

    System.out.println("Super");

  }

}

 

class Subclass extends Super {

  static void foo() {

    System.out.println("Subclass");

  }

}

A. Compile time error

B. Super

C. Subclass

D. Runtime error




 

10. What will be the output of below program?

 

package com.journaldev.java;

 

public class Test {

  public static void main(String[] args) {

    Subclass s1 = new Subclass();

    s1.foo(); // line 6

    Super s = new Subclass();

    s.foo(); // line 8

  }

}

 

class Super {

  private void foo() {

    System.out.println("Super");

  }

}

 

class Subclass extends Super {

  public void foo() {

    System.out.println("Subclass");

  }

}

A. Compile time error at line 6

B. Compile time error at line 8

C. Compile time error at both line 6 and 8

D. Works fine and prints “Subclass” two times.




 

11. What will be the output of below program?

 

import java.io.IOException;

 

public class Test {

  public static void main(String[] args) {

    try {

      throw new IOException("Hello");

    } catch (IOException | Exception e) {

      System.out.println(e.getMessage());

    }

  }

}

A. Compile-time error

B. Prints “Hello”

C. Runtime Error





 

12. What will be the output of below program?

 

public class Test {

  public static void main(String[] args) {

    String x = "abc";

    String y = "abc";

    x.concat(y);

    System.out.print(x);

  }

}

A. abcabc

B. abc

C. null




 

13. Which of the below are unchecked exceptions in java?

 

A. RuntimeException

B. ClassCastException

C. NullPointerException

D. IOException




 

14. What will be the output of below program?

 

package com.journaldev.java;

 

import java.io.IOException;

 

public class Test {

  public static void main(String[] args) {

    try {

      throw new Exception("Hello ");

    } catch (Exception e) {

      System.out.print(e.getMessage());

    } catch (IOException e) {

      System.out.print(e.getMessage());

    } finally {

      System.out.println("World");

    }

  }

}

A. Compile-time error

B. Hello

C. Hello World

D. Hello Hello World




 

15. Which of the following statement(s) are true for java?

 

A. JVM is responsible for converting Byte code to the machine-specific code.

B. We only need JRE to run java programs.

C. JDK is required to compile java programs.

D. JRE doesn’t contain JVM





 

16. Can we have two main methods in a java class?

 

A. Yes

B. No





 

17. Which of the following statements are true about annotations in java?

 

A. @interface keyword is used to create custom annotation

B. @Override is a built-in annotation in java

C. Annotations can’t be applied to fields in a class.

D. @Retention is one of the meta annotation in java.

E. Java annotation information gets lost when class is compiled.




 

18. Which of the following statements are true about Enum in java?

 

A. All java enum implicitly extends java.lang.Enum class.

B. Java enum can implement interfaces.

C. We can create instance of enum using new operator.

D. Enums can’t be used in switch statements.

E. Enum constants are implicitly static and final.



 

19. Which of the below are built-in class loaders in java?

 

A. Bootstrap Class Loader

B. Extensions Class Loader

C. Runtime Class Loader

D. System Class Loader

Grab the best assignment now!

PLACE AN ORDER

24*7SUPPORT

Tap to ChatGet Assistance