Inheritance, implementing inheritance, interface inheritance, JAVA Programming


Inheritance - is the inclusion of state and behavior of a base class in a derived class so that they are accessible in that derived class. The key benefit of Inheritance is that it gives the formal mechanism for

code reuse. Any shared piece of business logic may be moved from the derived class into the base class as part of refactoring method to improve maintainability of your code by avoiding code duplication. The existing class is called the superclass and the derived class is defined the subclass. Inheritance may also be illustrate as the process whereby one object requires characteristics from one or more other objects the similar way children accepts characteristics from their parents. There are basically two types of inheritances:


1. Implementation inheritance: You will extend an application's functionality by reusing functionality in the parent class by extending all or some of the operations already implemented. In Java, you can only add from one superclass. Implementation inheritance promotes reusability but improper use of class inheritance can gives programming nightmares by dividing encapsulation and building future changes a problem. With implementation inheritance, the subclass becomes hardly coupled with the superclass. This will build the design fragile because if you need to change the superclass, you have to know all the details of the subclasses to avoid breaking them. So when using implementation inheritance, make sure that the subclasses relay only on the nature of the superclass, not on the actual implementation.


2. Interface inheritance: That is also known as subtyping. Interfaces give a mechanism for specifying a relationship between otherwise unrelated classes, typically by specifying a set of common methods each implementing class must obtain. Interface inheritance provides the design concept of program to interfaces not to implementations. This also reduces implementation dependencies or the coupling between systems. In Java, you will implement any number of interfaces. This is more flexible and reliable than implementation inheritance because it won't restrict you into specific implementations which build subclasses difficult to maintain. So care could be taken not to divide the implementing classes by modifying the interfaces.


Posted Date: 7/25/2012 1:04:59 AM | Location : United States

Related Discussions:- Inheritance, implementing inheritance, interface inheritance, Assignment Help, Ask Question on Inheritance, implementing inheritance, interface inheritance, Get Answer, Expert's Help, Inheritance, implementing inheritance, interface inheritance Discussions

Write discussion on Inheritance, implementing inheritance, interface inheritance
Your posts are moderated
Related Questions

What will be the default values of all the elements of an array explained as an instance variable? If the array is an array of primitive types, then all the elements of the arr

Define Array ? Indexed collections of variable of similar data types or we can say a Set of organized variables of similar type.

What is an object's lock and which objects have locks? An object's lock is a mechanism that is used by multiple threads to get synchronized access to the object. A thread may i

What is Setter Methods explain with an example? Setter methods, also called as mutator methods, merely set the value of a field to a value specified through the argument to the

Classes are attached into the JVM as they are referenced by name in a class that is already running in the JVM. So, how is the staring class loaded? The very first class is espec

Extend the given drawing program (the version that allows undo and redo) as follows: a) Allow the user to select font and font size; user should also be able to boldface, underl

• Study and enhance the File System Simulator - See the FS_sim slide deck • New features - blockinfo - a new application that displays the information about the blocks in the file

How you Returning Values From Methods in java ? It's frequent meaningful to have a method return a value to the class which is known as it. This is accomplished through the ret

Can a human doctor be replaced through an Expert System? Give reasons to support your answer. Expert System is a computer system that simulates the knowledge and expertise of a