Вы находитесь на странице: 1из 4

COLLEGE OF COMPUTER STUDEIS

INFORMATION TECHNOLOGY DEPARTMENT

CCS0023L
(Object Oriented Programming)

EXERCISE

7
Dealing with Polymorphism and Inheritance

<STUDENT NAME>
<SECTION>
<DATE>
I. Objectives:

At the end of the experiment, students must be able to:

Cognitive
a) understand the effects of access modifiers in an inheritance relationship
b) understand the concept of Java abstract Classes

Psychomotor:
a) construct a program using 'extends' keyword to define an inheritance relationship
b) compile and debug the error of the program

Affective
a) appreciate the concept behind this experiment

II. BACKGROUND INFORMATION

Polymorphism is the ability of different objects to respond to the same message in different
ways. This means that different objects can have very different method implementations for
the same message.

Method Overloading is the process of declaring methods with the same name but different
parameter types.

Method Overriding allows a subclass to redefine methods of the same name from a
superclass

III. EXPERIMENTAL PROCEDURE:

1. Create an interface named Comparison whose method can be used to compare


two
Time objects. The methods will include isGreater, isLess, and isEqual.

2. 2.1. Create class Person with attributes name, age and gender.
2.2. Create class Student with attribute grade and,
2.3. Create class Teacher with attribute salary.
Note:
Class Student and Teacher must inherit from Person.
In main class, create and print two students and one teacher.
Apply inheritance, setter and getter.

Sample Output:
Student 2:
Name: Rachel
Age: 15
Gender: F
Grade: 2.50
3. Give a definition of a class named Arithmetic whose methods are three add() and multiply()
and one subtract() and divide().

 Parameter for add() and multiply() should be two, three and four int respectively.
 Parameter for subtract() and divide() should be two int.
 Applying method calling in the main(), test your program by calling the following
methods:

add(1,3)

add(1,3,4,5)

multiply(2,3,4)

multiply(1,1)

subtract(3,1)

divide(5,2)

IV. QUESTION AND ANSWER:

1. Consider the following two classes:


public class ClassA {
public void methodOne(int i) {
}
public void methodTwo(int i) {
}
public static void methodThree(int i) {
}
public static void methodFour(int i) {
}
}

public class ClassB extends ClassA {


public static void methodOne(int i) {
}
public void methodTwo(int i) {
}
public void methodThree(int i) {
}
public static void methodFour(int i) {
}
}
a. Which method overrides a method in the superclass?
b. Which method hides a method in the superclass?
c. What do the other methods do?
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
____________________________________________________________________________

Topic Polymorphism and Abstraction


Lab Activity No 7a
Lab Activity Comparison
CLO 1,3
Program execution (20)
Correct output (20)
Design of output (10)
Design of logic (20)
Standards (20)
Delivery (10)
TOTAL

Topic Polymorphism and Abstraction


Lab Activity No 7a
Lab Activity Person
CLO 1,3
Program execution (20)
Correct output (20)
Design of output (10)
Design of logic (20)
Standards (20)
Delivery (10)
TOTAL

Topic Polymorphism and Abstraction


Lab Activity No 7a
Lab Activity Arithmetic Operations
CLO 1,3
Program execution (20)
Correct output (20)
Design of output (10)
Design of logic (20)
Standards (20)
Delivery (10)
TOTAL

Вам также может понравиться