Java Basics Quiz 1

Java Basics Quiz 1

Time left: 10:00

1. What is the correct syntax for the main method in Java?

  • public static void main(String[] args)
  • public static void Main(String[] args)
  • public void main(String[] args)
  • public static void main(String args)

2. What is the size of int in Java?

  • 16-bit
  • 32-bit
  • 64-bit
  • 8-bit

3. Which of the following is not a Java keyword?

  • static
  • Boolean
  • void
  • private

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

  • true
  • false
  • 0
  • 1

5. Which method must be implemented by all threads?

  • start()
  • stop()
  • run()
  • main()

6. Which of the following is not a primitive data type in Java?

  • int
  • float
  • String
  • char

7. What is the result of 10 + 20 + "30" in Java?

  • 1030
  • 3030
  • 1230
  • 102030

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

  • 5, 10
  • 10, 5
  • 10, 10
  • 5, 5

9. What is the use of the "final" keyword in Java?

  • To mark a variable as read-only
  • To prevent method overriding
  • To prevent inheritance
  • All of the above

10. Which of the following is true about interfaces in Java?

  • Interfaces can have concrete methods
  • Interfaces can have constructors
  • Interfaces can be instantiated
  • Interfaces can have default methods