100 Most Asked Java Interview QnA Made by
Want More
instances of the class. 9. What is inheritance in Java? Inheritance is a mechanism in Java where a class can inherit properties and behaviors from another class. It allows for code reuse and creating a hierarchical relationship between classes. 10. What are the types of inheritance in Java? Java supports single inheritance, where a class can inherit from only one superclass, and multiple inheritance through interfaces, where a class can implement multiple interfaces. 11. What is polymorphism in Java? Polymorphism is the ability of an object to take on many forms. In Java, it allows objects of different classes to be treated as objects of a common superclass, enabling code flexibility and reusability. 12. What are the access modifiers in Java? Java provides four access modifiers: public, private, protected, and default (no modifier). They control the visibility and accessibility of classes, methods, and variables. 13. What is encapsulation in Java? Encapsulation is the process of hiding internal details and providing a public interface to interact with an object. It helps in achieving data abstraction and protects data from unauthorized access. 14. What is a constructor in Java? A constructor in Java is a special method that is used to initialize objects of a class. It is called automatically when an object is created and has the same name as the class. 15. What is the difference between a constructor and a method? A constructor is a special method used for object initialization and is called