What is the is a and has a relation ship in oops concept in
java?
Answer Posted / sandya
The relationships are the structure of the object. has-a
relationship can be described in Java code as member fields.
is-a relationship can be described in Java keyword extends.
The is-a relationship has an inheritance feature (like
"extends" or "implements") and has-a relationship has an
encapsulation feature (like private or protected modifier
used before each member field or method).
Let's look at one example. Translate the following perfect
sentences into Java code.
1. Pizza is a food. A Pizza has ingredients, a cost, and
a price.
public class Pizza extends Food //is-a relationship
{
int ingredients;//has-a relationship
double cost;
double price;
....
}
| Is This Answer Correct ? | 148 Yes | 13 No |
Post New Answer View All Answers
Difference between process and thread?
What happens when a thrown exception is not handled?
Does printwriter create a file?
Which method cannot be overridden in java?
What is the java project architecture?
What is floor math?
Under what conditions is an object’s finalize() method invoked by the garbage collector?
Why is java called the platform independent programming language?
Draw a UML class diagram for the code fragment given below: public class StringApplet extends Applet { private Label sampleString; private Button showTheString; private ButtonHandler bHandler; private FlowLayout layout; public StringApplet() { sampleString = new Label(" "); showTheString = new Button (" Show the String"); bHandler = new ButtonHandler(); layout = new FlowLayout(); showTheString.addActionListener(bHandler); setLayout(layout); add(sampleString); add(showTheString); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { samplestring.setText("Good Morning"); } } } Note: The methods need not be indicated on the diagram.
Can you call a method in a method?
What are abstract methods in java?
What are basic keywords?
What is the purpose of default constructor?
Explain java coding standards for methods?
What is use of set in java?