![]() ![]() Inheritance is used to use the existing features of the class.ĭ. Using inheritance, we can increase features of class or method by overriding.Ĭ. We can reuse the code from the base class.ī. □ We use inheritance in java for the following reasons:Ī. Implements: implements keyword is used for developing the inheritance between a class and interface. □ Inheritance can be implemented or achieved by using two keywords:Įxtends: extends is a keyword that is used for developing the inheritance between two classes and two interfaces. How is Inheritance implemented/achieved in Java? □ Object class is the superclass of every other class in Java.ġ1. Which class in Java is super class of every other class? This is a very good example of Is-A relationship.ġ0. It is implemented using “extends” keyword. □ Is-A relationship represents inheritance. The existing class is called parent class and the new class is called child class. In other words, inheritance is a process where a child class acquires all the properties and behaviors of parent class. □ The technique of creating a new class by using an existing class functionality is called inheritance. □ A method that is used to retrieve/get the value of a variable or return the value of the private member variable is called getter method.Ī method that is used for updating or setting the value of a variable is called setter method. ![]() What is getter and setter method in Java? □ If we don’t use encapsulation in a program, fields will not be private and could be accessed by anyone from outside the class.ħ. What would happen if we do not use Encapsulation in a program? □ If each variable is declared as private in the class, it is called tightly encapsulated class in Java.Ħ. What is tightly encapsulated class in Java? □ Data hiding is a technique by which we prevent to access data members (variables) directly from outside the class so that we can achieve security on data.īy declaring data members (variables) as private, we can achieve or implement data hiding.ĥ. What is Data hiding in Java? How to achieve it programmatically? Provide the public setter and getter methods in the class to set/modify the value of variable.Ĥ. Declaring instance variable of class as private so that it cannot be accessed directly by anyone from outside the class.Ģ. □ There are two points thereby we can achieve or implement encapsulation in Java program.ġ. How to achieve or implement encapsulation in Java? □ The process of binding data and corresponding methods (behavior) together into a single unit is called encapsulation.ģ. Polymorphism: Using various methods with same name Inheritance: Using code written in a class inside other classes Abstraction: Protecting data of a class from being accessed by members of another classĮncapsulation: Hiding data of class from other classes ![]()
0 Comments
Leave a Reply. |