Advantages of Inheritance in java.

Answer Posted / josh

Inheritance can lead to a combinatorial explosion of
classes. Composition should be somewhere in the code
oftentimes. For example, an Employee object can "contain" a
PaymentType object, a PaymentSchedule object, and a
PaymentMethod object. Each of those 3 objects are their own
classes. The Employee class creates instance of those
classes and "holds" on to them. From there, a higher class
such as a PayrollSystem can look at an Employee object and
query that Employee about that Employee's information
(namely its object contents). With composition, your code is
highly decoupled, meaning that those 3 object held by
Employee can easily be held by some other class (hence code
reuse). It is important to note that PaymentSchedule,
PaymentMethod, and PaymentType should be interfaces which
have multiple concrete implementations to them (ie. a
PaymentType interface could be implemented with an Hourly,
Salary, or SalaryWithCommission class for a given Employee).
Inheritance causes high coupling and reduces code
reusability. It helps to write a UML static(class) diagram
before typing up code

Is This Answer Correct ?    10 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens when I use / and % with a negative numerator?

536


What are the types of java languages?

519


What is another word for methodology?

521


What is the largest number a double can hold?

563


Write down program for following scenario. Use java coding standard. You have array list with some words in it..we will call it as dictionary….and you have a arbitrary string containing some chars in it. You have to go through each word of dictionary and find out if that word can be constructed with the help of chars from arbitrary string given. If you find the word print it else print none.

2282






What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?

1938


How to change value in arraylist java?

506


Explain why wait(), notify() and notifyall() methods are in object class rather than in thread class?

560


What is the importance of static variable?

590


Differentiate between stringbuffer and string?

597


What are the advantages of java over cpp?

553


What is api in java?

539


Which class should you use to obtain design information about an object in java programming?

645


What is the significance of java packages?

614


What is getkey () in java?

577