



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




public class USFPerson { protected String name; protected String id;
public USFPerson(String name, String id) { this.name = name; this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } Public String getId() { return id; } public void setId(String id) { this.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; } }
Student s = new Student("John Smith", "1101101", 3.5); USFPerson p1 = new USFPerson("Jane Eyre", "101101101"); USFPerson p2 = s;
System.out.println(s.getName()); System.out.println(p1.getName()); System.out.println(p2.getName());
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());
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(((Studnet) p1).getGPA()); System.out.println(((Student) p2).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, setID
public 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); } }
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() {
public abstract class USFPerson { protected String name; protected String id;
public USFPerson(String name, String id) { this.name = name; this.id = id; }
// getName, getID, setName, setID
public abstract double getEmailQuota(); }
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, setGPA
public double getEmailQuota() { return STUDENT_QUOTA; } }
class FlyingAnimal class Mammal { { ... ... void move() void move() { { System.out.println("Flying!"); System.out.println("Walking"); } } } }
class Bat extends FlyingAnimal, Mammal { ... }
Bat b = new Bat(); b.move() <== What would this do?
public interface Comparable { public int compareTo(Object o); }
Comparable c1 = new Integer(2); Comparable c2 = new Integer(3); Comparable c3 = new String("foo"); Comparable c4 = new String("bar");
System.out.println(c1.compareTo(c2)); System.out.println(c3.compareTo(c4));
Comparable c1 = new Integer(2); Comparable c4 = new String("bar");
System.out.println(c1.compareTo(c4));
class Bat exends Mammal implements FlyingAnimal {
}