Java Basics Quiz 3

Java Basics Quiz 3

Time left: 10:00

1. What is the use of the "import" statement in Java?

  • To import classes from other packages
  • To import data from a database
  • To import files from the file system
  • To import methods from other classes

2. What is the correct syntax for a single-line comment in Java?

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

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

  • 5
  • 10
  • 15
  • 50

4. Which of the following is not an access modifier in Java?

  • public
  • private
  • protected
  • internal

5. What is the correct way to declare an array in Java?

  • int arr[] = new int[5];
  • int arr[];
  • int[] arr;
  • All of the above

6. Which of the following is used to declare an abstract method in Java?

  • void method() {};
  • abstract void method();
  • void method();
  • abstract method();

7. Which of the following is not a valid loop construct in Java?

  • for
  • while
  • do-while
  • foreach

8. What is the output of the following code?
                int a = 5;
                int b = 10;
                int c = a + b;
                c += 5;
                System.out.println(c);
            

  • 15
  • 20
  • 25
  • 30

9. Which of the following is true about Java?

  • Java is a platform-independent language
  • Java supports automatic memory management
  • Java supports multithreading
  • All of the above

10. What is the use of the "this" keyword in Java?

  • To refer to the current object
  • To refer to the superclass
  • To refer to a static method
  • To refer to the constructor