Core Java Quiz: Packages And Interfaces In Java

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Themes
T
Themes
Community Contributor
Quizzes Created: 420 | Total Attempts: 896,840
Questions: 10 | Attempts: 829

SettingsSettingsSettings
Core Java Quiz: Packages And Interfaces In Java - Quiz

This is a core Java quiz consisting of questions related to packages and interfaces. You can easily solve it and score 100% marks on this test if you consider yourself a hardcore programmer. Packages in Java are a group of similar types of classes, interfaces, and sub-packages. These are basically used to group the related classes. Play the below quiz if your concepts are clear in Java language. Shall we begin it now? Best of luck, buddy!


Questions and Answers
  • 1. 

     __________ Keyword is used to create Package in java.

    • A.

      Class

    • B.

      Pack

    • C.

      Interface

    • D.

      None

    Correct Answer
    D. None
    Explanation
    The keyword "package" is used to create a package in Java. Packages are used to organize classes and interfaces into namespaces, making it easier to manage and maintain large codebases. By using the "package" keyword followed by the package name, developers can create a package and place related classes and interfaces within it. The "class" keyword is used to define a class, the "interface" keyword is used to define an interface, and "None" is not a valid keyword in Java.

    Rate this question:

  • 2. 

    The TreeMap class is used to implement

    • A.

      Map interface

    • B.

      NavigableMap 

    • C.

      AbstractMap Class

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The TreeMap class in Java is used to implement the Map interface, which allows us to store key-value pairs. It also implements the NavigableMap interface, which provides navigation methods for accessing elements based on their keys. Additionally, TreeMap is a subclass of the AbstractMap class, which provides a skeletal implementation of the Map interface. Therefore, the correct answer is "all of the above" as TreeMap can be used to implement all of these interfaces.

    Rate this question:

  • 3. 

    Which inheritance is achieved using interface in Java?

    • A.

      Multiple inheritance

    • B.

      Single inheritance

    • C.

      Multilevel inheritance

    • D.

      None of the above

    Correct Answer
    A. Multiple inheritance
    Explanation
    In Java, multiple inheritance is achieved using interfaces. Unlike classes, interfaces allow a class to inherit from multiple interfaces. This means that a class can inherit and implement multiple interfaces, allowing it to inherit the properties and methods defined in each interface. This enables the class to exhibit behavior from multiple sources, achieving multiple inheritance.

    Rate this question:

  • 4. 

    Methods of the interface must not be ___ in nature.

    • A.

      Static

    • B.

      Final

    • C.

      Native 

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The correct answer is "all of the above". This means that methods of the interface must not be static, final, or native in nature. In Java, static methods belong to the class itself and cannot be overridden by implementing classes. Final methods cannot be overridden or modified by implementing classes. Native methods are implemented in a language other than Java, typically for low-level operations. Therefore, all of these options are incorrect for methods of an interface.

    Rate this question:

  • 5. 

    How many classes we are able to extend in Java?

    • A.

      Only one class

    • B.

      Two class

    • C.

      Three class

    • D.

      Four class

    Correct Answer
    A. Only one class
    Explanation
    In Java, a class can only extend one other class. This is known as single inheritance. This means that a subclass can inherit the properties and methods of only one superclass. However, Java does allow for multiple interfaces to be implemented by a class, which provides a form of multiple inheritance through interfaces. But when it comes to extending classes, Java only allows for a single class to be extended.

    Rate this question:

  • 6. 

    Which keyword is used for using interface in class?

    • A.

      Extend

    • B.

      Throw

    • C.

      Implements

    • D.

      None of the above

    Correct Answer
    C. Implements
    Explanation
    The keyword "implements" is used for using an interface in a class. When a class implements an interface, it is required to provide implementations for all the methods defined in that interface. This allows the class to inherit the properties and behaviors defined in the interface, making it possible to achieve multiple inheritance in Java. The "extend" keyword is used for inheriting from a superclass, while the "throw" keyword is used for throwing exceptions. Therefore, neither of these keywords is used for using an interface in a class.

    Rate this question:

  • 7. 

    Which terms are included inside the package?

    • A.

      Classes

    • B.

      Method

    • C.

      Interfaces

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The correct answer is "All of the above" because the question asks which terms are included inside the package, and all three options (classes, methods, and interfaces) are commonly included in packages. Therefore, "All of the above" is the correct answer as it encompasses all the options given.

    Rate this question:

  • 8. 

    Which of the following package are built-in packages?

    • A.

      Lang

    • B.

      Java

    • C.

      Util

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The correct answer is "all of the above" because all three options (lang, java, util) are built-in packages in Java. The lang package contains classes that are fundamental to the language, such as Object and String. The java package contains classes for core functionality, such as input/output and networking. The util package contains utility classes, such as collections and date/time manipulation. Therefore, all of these packages are included by default in Java and do not require any additional installation or setup.

    Rate this question:

  • 9. 

    A package can be renamed without renaming the directory in which the classes are stored.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    A package cannot be renamed without renaming the directory in which the classes are stored. In Java, the package name and the directory structure are closely related. The package name must match the directory structure in order for the compiler to locate the classes correctly. Therefore, if a package is renamed, the corresponding directory must also be renamed to match the new package name.

    Rate this question:

  • 10. 

    Which of these can be used to fully abstract a class from its implementation?

    • A.

      Objects

    • B.

      Packages

    • C.

      Interfaces

    • D.

      None of the mentioned​​

    Correct Answer
    C. Interfaces
    Explanation
    Interfaces can be used to fully abstract a class from its implementation. An interface defines a contract that a class must adhere to, specifying the methods that the class must implement. By programming to the interface rather than the specific implementation, the class can be easily swapped out with a different implementation without affecting the rest of the code. This allows for loose coupling and promotes modularity and flexibility in the design.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 30, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 08, 2022
    Quiz Created by
    Themes
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.