Week008 LabEx
Week008 LabEx
Objective/s:
At the end of this activity, you should be able to:
· Utilize the knowledge gained in this module to create an application that relies on
polymorphism and inheritance
· Understand the difference between polymorphism and inheritance
· Use an abstract class and an interface
Procedure:
Create a NetBeans project for this activity. The project name should be as follows:
Project Name: Lab007_<lastname_firstname>
Example: Lab007_Blanco_Maria
Compress the NetBeans project into .rar or .zip format and then upload to the link
provided in the LMS.
Only NetBeans project compressed in .rar or .zip format will be accepted.
1. StudentRecord
a. Class Names: Lab8Main (main class)
b. StudentRecord:
public class StudentRecord {
//these are the attributes
private String name;
private double mathGrade;
private double englishGrade;
Assessments
private double scienceGrade;
//custom method
public double computeAverageGrade(){
return (this.mathGrade + this.englishGrade +
this.scienceGrade)/3;
}
}
c. ComputerScienceStudentRecord
The StudentRecord class is given for your reference. The following are your tasks:
Computer Programming 2
Polymorphism and Inheritance 3
Assessments
1: Create a class that will inherit A: extends
the attributes and methods of the
StudentRecord class. What B: implements
keyword is used in order create a
parent-child relationship between
two classes? C: extension
D: overloads
C:
@overloads
public ComputerScienceStudentRecord (final
name, final mathGrade, final englishGrade, final
scienceGrade) {
// body
Computer Programming 2
Polymorphism and Inheritance 5
D:
@overloads
public ComputerScienceStudentRecord (final
String name, final int mathGrade, final int
englishGrade, final int scienceGrade) {
// body
}
A: this
4: Now set the values of the
parameters to the attributes of
the class. What keyword will you
use?
B: super
D: private computerProgrammingGrade = 0;
Assessments
A:
6: Now override the @override
computeAverageGrade. How will public double computeAverageGrade()
you do that? //body
}
B:
@overrides
public double computeAverageGrade()
//body
}
C:
@overrides
public double super.computeAverageGrade()
//body
}
D:
public double super.computeAverageGrade()
//body
}
A: Both Inheritance and Polymorphism
7: What pillar of Object Oriented
Programming is used when we
override a method from the super
type?
B: Polymorphism only since we are using the
method to morph into another with different
implementation
C: Inheritance only.
A: A only.
10: Create a test class with a main
method. Create an instance of
ComputerScienceStudentRecord.
Which of the following is the
possible way to do that? B: B only.
A. ComputerScienceStudentRecor
d studentRecord = C: Both A & B.
ComputerScienceStudentRecor
d(“List Marie”, 91, 92, 93)
B. StudentRecord studentRecord
= D: None of the choices.
ComputerScienceStudentRecord(“
List Marie”, 91, 92, 93)
Assessments