Essay Available:
page:
2 pages/≈550 words
Sources:
-1
Style:
APA
Subject:
IT & Computer Science
Type:
Coursework
Language:
English (U.S.)
Document:
MS Word
Date:
Total cost:
$ 12.96
Topic:
Composition of "Is-A" and “Has-A” Relationship in JAVA
Coursework Instructions:
Give an example of a three-level "Is-A" hierarchy and a three-level "Has-A" hierarchy other than the ones discussed in the lecture. (JAVA)
write code and explanation
make sure it can be transferred to notepad and can be saved
Coursework Sample Content Preview:
Java programming: “IS A” and “Has A”
Name:
Institutional Affiliation:
“IS A”
Hierarchical inheritance is a mechanism where two or more sub-classes acquire properties from similar super class. The relationship “IS A” is simply a parent to child relationship (Gosling, Holmes & Arnold, 2005). Below is a Java code segment demonstrating a three level “IS A” hierarchical relationship.
// Java program to illustrate the
// concept of a three level "IS A" Hierarchical //inheritance
class Animal{
public void sleep() {
System.out.println("is sleeping ");
}
}
class Sheep extends Animal {
public void baa() {
System.out.println("is baasing");
}
}
class Dog extends Animal {
public void barks() {
System.out.println("is barking");
}
}
class Lion extends Animal {
public void grunts() {
System.out.println("is grunting");
}
}
// Here is the driver class
public class All {
public static void main(String[] args)
{
//creating an object of class sheep
//and calling the inherited method and //its newly created method
Sheep s1 = new Sheep();
s1.baa();
s1.sleep();
}
}
Descriptions of the above program
The program is made up of one superclass which is class Animal. The superclass is then inherited by three more classes which are class Dog, class Sheep and class Lion. All these classes have acquired the method described in class Animal. Since the superclass Animal has the method sleep (), all its subclasses inherit it in their operations. This demonstrates a three-level hierarchical inheritance since three subclasses...
Get the Whole Paper!
Not exactly what you need?
Do you need a custom essay? Order right now:
👀 Other Visitors are Viewing These APA Essay Samples:
-
Java IO Input and Output Classes
1 page/≈275 words | No Sources | APA | IT & Computer Science | Coursework |
-
Explaining JAVA Appending
1 page/≈275 words | No Sources | APA | IT & Computer Science | Coursework |
-
Evaluating Effectiveness of GIMP, Gmail, and YouTube Tutorials for Novice Users
1 page/≈275 words | No Sources | APA | IT & Computer Science | Coursework |