COMP2396
Loading...
Searching...
No Matches
testDrive.java
Go to the documentation of this file.
1package chapter2;
2// Lecture 2 (ch2) mentioned:
3// Can use super class to hold subclass objects
4// e.g. Dog d = new Dog();
5// here, Object untitled = new AdvancedObject();
6// is valid
7// Overriding methods in subclass is possible
8// but if the method is not in the superclass, it will not be accessible
9// also the instance variable of the subclass will not be accessible
10class Object {
11 String name;
12 int UniqueID;
13
14 void exportInfo() {
15 System.out.println("Hi! I am " + name + " and my ID is " + UniqueID);
16 }
17}
18
19class AdvancedObject extends Object {
20 String description;
21
22 @Override
23 void exportInfo() {
24 System.out.print("Hi! I am " + name + " and my ID is " + UniqueID);
25 System.out.println(" and my description is " + description);
26 }
27}
28
29class testDrive {
30 public static void main(String[] args) {
31 Object untitled = new AdvancedObject();
32 untitled.name = "Untitled";
33 untitled.UniqueID = 10;
34 // untitled.description = "I am an untitled object";
35 untitled.exportInfo();
36 }
37}