Java Basics Quiz 4

Java Basics Quiz 4

Time left: 10:00

1. What is the correct way to create a new instance of a class in Java?

  • ClassName obj = new ClassName();
  • ClassName obj = ClassName.new();
  • ClassName obj = new();
  • ClassName obj = ClassName();

2. What is the correct syntax to create a new array in Java?

  • int[] arr = new int[5];
  • int arr = new int[5];
  • int[] arr = new int(5);
  • int arr = new int(5);

3. What is the correct way to inherit a class in Java?

  • class SubClass extends SuperClass
  • class SubClass implements SuperClass
  • class SubClass inherits SuperClass
  • class SubClass inherits SuperClass

4. What is the output of the following code?
                int[] arr = {1, 2, 3, 4, 5};
                System.out.println(arr[2]);
            

  • 1
  • 2
  • 3
  • 4

5. What is the correct syntax for a multi-line comment in Java?

  • // comment
  • /* comment */
  • # comment #

6. What is the output of the following code?
                int x = 5;
                int y = 10;
                int z = x + y;
                System.out.println(z);
            

  • 5
  • 10
  • 15
  • 20

7. What is the correct way to call a static method in Java?

  • ClassName.methodName();
  • objectName.methodName();
  • methodName();
  • None of the above

8. What is the default value of a boolean variable in Java?

  • true
  • false
  • 0
  • 1

9. What is the purpose of the "this" keyword in Java?

  • To refer to the current object instance
  • To refer to a static member
  • To refer to a superclass
  • None of the above

10. Which of the following statements is true about Java?

  • Java is a platform-dependent language
  • Java supports multiple inheritance through classes
  • Java is a statically-typed language
  • Java does not support polymorphism