What is a package?-

?– A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management. In Java, a package is a way to organize related classes and interfaces into a single unit. It helps in avoiding naming conflicts and provides a modular structure to the code. A package … Read more

What are inner class and anonymous class?-

Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors. … Read more

What modifiers may be used with top-level class?-

public, abstract and final can be used for top-level class. In Java, a top-level class (i.e., a class that is not a nested or inner class) can have the following modifiers: public: The class can be accessed from any other class. (default, no modifier): If no access modifier is specified, the class is only accessible … Read more

What is the difference between superclass and subclass?-

?– A super class is a class that is inherited whereas sub class is a class that does the inheriting. In Java, a superclass (or parent class) is a class that is extended by another class, known as the subclass (or child class). The relationship between a superclass and a subclass is part of the … Read more

What is the difference between this() and super()?

this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor. In Java, this() and super() are both used to invoke constructors, but they are used in different contexts and have different purposes: this(): It is used to invoke the current class constructor. … Read more