1.
__________ Keyword is used to create Package in java.
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.
2.
The TreeMap class is used to implement
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.
3.
Which inheritance is achieved using interface in Java?
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.
4.
Methods of the interface must not be ___ in nature.
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.
5.
How many classes we are able to extend in Java?
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.
6.
Which keyword is used for using interface in class?
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.
7.
Which terms are included inside the package?
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.
8.
Which of the following package are built-in packages?
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.
9.
A package can be renamed without renaming the directory in which the classes are stored.
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.
10.
Which of these can be used to fully abstract a class from its implementation?
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.