COMP2396
Loading...
Searching...
No Matches
test.java
Go to the documentation of this file.
1package chapter2;
2
3/**
4 * Conclusion: Object is like a remote control
5 * Can only access the buttons that are on the remote control
6 * (methods and instance variables)
7 * But the behavior of the buttons is determined by the actual object
8 * (subclass)
9 */
10@SuppressWarnings("unused")
11class base {
12 int instance_variable;
13 void method() {
14 // do nothing
15 }
16}
17
18@SuppressWarnings("unused")
19class extended extends base {
20 int another_instance_variable;
21 @Override
22 void method() {
23 System.out.println("Does something " + another_instance_variable);
24 }
25 // new method
26 void newMethod() {
27 System.out.println("Does something new");
28 }
29}
30
31public class test {
32 public static void main(String[] args) {
33 base example = new extended();
34 example.method();
35 // example.newMethod(); // compiler error
36 }
37}
static void main(String[] args)
Definition test.java:32