Essay Available:
Pages:
2 pages/≈550 words
Sources:
Check Instructions
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:
You Might Also Like Other Topics Related to animal right:
- Why Prohibition of Dogfighting Necessary7 pages/≈1925 words | APA | Literature & Language | Essay |
- Protozoans, Parasitic Diseases Precautions, Hookworm, and 'Life Cycle' of a Parasite2 pages/≈550 words | APA | Health, Medicine, Nursing | Essay |
- Structure and Function of Living Systems through Process and Rationale Lesson Plan2 pages/≈550 words | APA | Education | Essay |
- Call and Response Tradition: Stirring Things Up1 page/≈275 words | APA | Literature & Language | Essay |
- Roles of Nurses on Health Promotion and Infection Control5 pages/≈1375 words | APA | Health, Medicine, Nursing | Essay |
- Understanding the Vegetarian Diet1 page/≈275 words | APA | Health, Medicine, Nursing | Essay |
- Using Symbols to Establish Brands2 pages/≈550 words | MLA | Social Sciences | Other (Not Listed) |