



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of computer science cs112 course notes from the university of san francisco, focusing on inheritance and interfaces concepts. It explains the 'is-a' relationship, data members and methods inheritance, and provides examples of student class extending usfperson. Additionally, it covers polymorphism, abstract classes, and abstract methods.
Typology: Study notes
1 / 27
This page cannot be seen from the preview
Don't miss anything!




















public class Student extends USFPerson {
protected double gpa;public Student(String name, String id, double gpa){
super(name, id);this.gpa = gpa; } public double getGpa(){
return gpa; } public void setGpa(double gpa){
this.gpa = gpa; } }
Student s = new Student("John Smith", "1101101", 3.5);USFPerson p1 = new USFPerson("Jane Eyre", "101101101");USFPerson p2 = s;System.out.println(s.getGPA());System.out.println(p1.getGPA());System.out.println(p2.getGPA());
Student s = new Student("John Smith", "1101101", 3.5);USFPerson p1 = new USFPerson("Jane Eyre", "101101101");USFPerson p2 = s;System.out.println(s.getGPA());Student s1 = (Student) p1;System.out.println(s1.getGPA());Student s2 = (Student) p1;System.out.println(s2.getGPA());
public class USFPerson {
protected String name;protected String id;public USFPerson(String name, String id) {
this.name = name;this.id = id; } // getName, setName, getID, setIDpublic void print() {
System.out.pritnln("Name: " + name);System.out.pritnln("ID:
" + id);
public class Student extends USFPerson {
protected double gpa;public Student(String name, String id, double gpa){
super(name, id);this.gpa = gpa; } public double getGpa(){
return gpa; } public void setGpa(double gpa){
this.gpa = gpa; } public void print() {
System.out.pritnln("Name: " + name);System.out.pritnln("ID:
" + id);
System.out.println("GPA:
" + gpa);
USFPerson personArray[] = new USFPerson[4];personArray[0] = new USFPerson("Emily Dickison", "1101101");personArray[1] = new USFStudent("Anton Chekhov", "111010011", 3.5);personArray[2] = new USFStudent("Doris Lessing", "101010101", 3.8);personArray[3] = new USFPerson("Charles Dickens", "11111101");for (int i = 0; i < 4; i++)
personArray[i].print();
public class Student extends USFPerson {
public final static double STUDENT_QUOTA = 3000000.0;protected double gpa;public Student(String name, String id, double gpa){
super(name, id);this.gpa = gpa; } // getGPA, setGPApublic double getEmailQuota(){
return STUDENT_QUOTA; } }