- Home
- Interview Questions
- Java
Nested types are used for two separate purposes, that are related to encapsulations
A type may be nested because it needs especially intimate access to the internals of another type by being a member type, it has access in the same way that member variables and methods do, and can bend the rules of encapsulation.
A type may be only required for a very specific reason, and in a very small section of code. It should be tightly localized, as it is really part of the implementation detail and should be encapsulated away from the rest of the system.
Polymorphism means that one object can take the form, or place of, an object of a different type. Polymorphism can exist when one class inherits another. It can also exist when a class implements an interface.
A static member typeis much like a regular top-level type.however, it is nested within the namespace of another type.
Queues are working by First in First Out (FIFO) rule but the stacks are working by Last in First Out (LIFO) rule.
Yes sometimes we can use but the class may be a descendant of another class also in this case the interface is the only option.