Java Fundamentals Quiz Quiz

  1. Question 1

    Which keyword is used to prevent a method from being overridden in a subclass?

    1. static
    2. volatile
    3. final
    4. synchronized
    5. transient
  2. Question 2

    What is the primary purpose of the 'garbage collector' in Java?

    1. To optimize code execution speed
    2. To automatically manage memory by reclaiming unused objects
    3. To handle exceptions and errors
    4. To prevent memory leaks by allocating more memory
    5. To ensure code security against vulnerabilities
  3. Question 3

    Which data structure follows the Last-In-First-Out principle?

    1. Queue
    2. Linked List
    3. Tree
    4. Stack
    5. Heap
  4. Question 4

    What is the purpose of the 'interface' keyword in Java?

    1. To define a class constructor
    2. To create a concrete class
    3. To define a contract that classes can implement
    4. To declare a variable
    5. To create a package
  5. Question 5

    Which of the following is a valid way to create a new instance of a class called 'MyClass'?

    1. MyClass.new()
    2. create MyClass()
    3. new MyClass()
    4. MyClass()
    5. instanceof MyClass
  6. Question 6

    What is the role of the 'extends' keyword in Java?

    1. To implement an interface
    2. To define a new package
    3. To inherit properties and methods from another class
    4. To declare a constant variable
    5. To throw an exception
  7. Question 7

    Which of these is a primitive data type in Java?

    1. String
    2. Integer
    3. Boolean
    4. Array
    5. Object
  8. Question 8

    What is the purpose of the 'try-catch' block in Java?

    1. To define a loop
    2. To handle exceptions
    3. To create a new thread
    4. To define a conditional statement
    5. To declare a method
  9. Question 9

    What is the difference between '==' and '.equals()' in Java when comparing objects?

    1. '==' compares the values, '.equals()' compares the references
    2. '==' compares the references, '.equals()' compares the values based on the object's implementation
    3. Both compare the memory addresses
    4. Both compare the data types
    5. There is no difference
  10. Question 10

    What does the term 'polymorphism' refer to in object-oriented programming?

    1. The ability of an object to take on many forms
    2. The process of hiding data within a class
    3. The ability to create multiple threads
    4. The process of memory allocation
    5. The act of writing comments in code