Search Tutorials


Java Packages MCQ Questions And Answers | JavaInUse

Java Packages MCQ Questions And Answers

Q. What is a Java package?

A. A collection of classes and interfaces
B. A data structure
C. An executable file
D. A loop statement

Q. Which keyword is used to import a package in Java?

A. include
B. import
C. require
D. from

Q. Which of the following is true about Java packages?

A. Packages can be nested
B. Packages can be imported within other packages
C. Packages can contain only interfaces
D. Packages are not used in Java programming

Q. What is the access modifier for a class within a package that allows it to be accessed by any other class?

A. public
B. private
C. protected
D. default

Q. Which of the following is a predefined package in Java?

A. mypackage
B. javapackage
C. util
D. program

Q. What is the benefit of using packages in Java?

A. Easier code organization and management
B. Faster code execution
C. Greater security
D. Better user interface

Q. How do you create a package in Java?

A. Using the "create package" keyword
B. Adding a class to a folder with the package name
C. Using the "package" keyword at the beginning of a Java file
D. Using the "new" keyword

Q. Can two classes in the same package have the same name?

A. Yes, as long as they are in different folders
B. No, class names in the same package must be unique
C. Only if one class is public and the other is private
D. Only if one class is abstract and the other is concrete

Q. What is the purpose of the Predicate functional interface in Java 8?

A. To produce results
B. To consume values
C. To filter elements based on a condition
D. To transform values

Q. Which keyword is used to access a class from a different package in Java?

A. import
B. access
C. importclass
D. package

Q. Which of the following statements is true about Java Packages?

A.
    Packages can be nested with dots in their name.
    
B.
    Packages in Java are used to group related classes.
    
C.
    Packages are mainly used for organizing code and avoiding naming conflicts.
    
D.
    Packages can only contain interfaces and abstract classes.
    





Q. How can you import all the classes from a package in Java?

A.
    import package.*;
    
B.
    import package.all;
    
C.
    import all.package.*;
    
D.
    import all.package;
    

Q. Which of the following is the correct way to access a class from a different package in Java?

A.
    import different.package.ClassName;
    
B.
    import ClassName from different.package;
    
C.
    import package.different.ClassName;
    
D.
    import package.different;
    

Q. What is the purpose of Java Packages?

A.
    To organize classes into logical groups.
    
B.
    To provide security to classes.
    
C.
    To limit the access to classes.
    
D.
    To execute multiple classes simultaneously.
    

Q. How can you create a new package in Java?

A.
    Create a new directory with the package name and move the class files into it.
    
B.
    Use the createPackage() method.
    
C.
    Use the package keyword at the beginning of the Java file.
    
D.
    Use the import keyword.
    

Q. Which symbol is used to denote a subpackage in Java?

A.
    .
    
B.
    /
    
C.
    \\
    
D.
    :
    

Q. Which of the following is a predefined package in Java?

A.
    java.util
    
B.
    myPackage
    
C.
    com.app
    
D.
    mainPackage
    

Q. How is the access level or visibility of a class modified in Java?

A.
    Using the protected keyword.
    
B.
    Using the hidden keyword.
    
C.
    Using the visible keyword.
    
D.
    Using the public, private, or protected keywords.
    

Q. When importing classes from the java.awt package, which of the following would import all classes in the package?

A.
    import java.awt.*;
    
B.
    import java.awt.all;
    
C.
    import all.java.awt.*;
    
D.
    import all.java.awt;
    

Q. Which of the following statements is true about Java packages?

A.
    A package can contain only one class.
    
B.
    Classes in the same package cannot access each other.
    
C.
    Package names must always be unique.
    
D.
    A class can belong to multiple packages.