Vous êtes sur la page 1sur 5

COLLEGE OF COMPUTER STUDIES & MULTIMEDIA

ARTS

CCS0023/L
(Object Oriented Programming)

EXERCISE

7
Dealing with Polymorphism and Inheritance

score

Jash Mhaynard Vasquez


Name of Student Name of Professor

Date Performed Date Submitted

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:
3. Give a definition
Class Studentof a class
and named
Teacher Arithmetic
must whose
inherit from methods are three add() and multiply()
Person.
and one subtract() and divide().
In main class, create and print two students and one teacher.
Apply inheritance, setter and getter.
 Parameter for add() and multiply() should be two, three and four int respectively.
 Parameter for subtract() and divide() should be two int.
Sample Output:
 Applying method calling in the main(), test your program by calling the following
Student 2:
methods:
Name: Rachel
Age: 15
add(1,3)
Gender: F
Grade: 2.50
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?
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
____________________________________________________________________________
V. ASSESSMENT

Department Information Technology


Subject Code ITPROG3
Description OBJECT-ORIENTED PROGRAMMING
Term/Academic Year

Note: The following rubrics/metrics will be used to grade students’ output in the lab
Exercise 7.

Program (100 pts.) (Excellent) (Good) (Fair) (Poor)


Program Program executes Program executes Program executes Program does not
execution (20pts) correctly with no with less than 3 with more than 3 execute (10-11pts)
syntax or runtime errors (15-17pts) errors (12-14pts)
errors (18-20pts)
Correct output Program displays Output has minor Output has multiple Output is incorrect
(20pts) correct output with errors (15-17pts) errors (12-14pts) (10-11pts)
no errors (18-20pts)
Design of output Program displays Program displays Program does not Output is poorly
(10pts) more than expected minimally expected display the required designed (5pts)
(10pts) output (8-9pts) output (6-7pts)
Design of logic Program is logically Program has slight Program has Program is incorrect
(20pts) well designed (18- logic errors that do significant logic (10-11pts)
20pts) no significantly errors (3-5pts)
affect the results (15-
17pts)
Standards Program code is Few inappropriate Several inappropriate Program is poorly
(20pts) stylistically well design choices (i.e. design choices (i.e. written (10-11pts)
designed (18-20pts) poor variable names, poor variable names,
improper improper
indentation) (15- indentation) (12-
17pts) 14pts)
Delivery The program was The program was The program was The program was
(10pts) delivered on time. delivered a day after delivered two days delivered more than
(10pts) the deadline. (8- after the deadline. (6-two days after the
9pts) 7pts) deadline. (5pts)

Topic Dealing with Polymorphism and


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

Topic Declaring classes


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

Topic Declaring classes


Lab Activity No 7c
Lab Activity Arithmetic operations
CLO 1,2
Program execution (20)
Correct output (20)
Design of output (10)
Design of logic (20)
Standards (20)
Delivery (10)
TOTAL

Vous aimerez peut-être aussi