-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathHelloWorld.java
37 lines (28 loc) · 1020 Bytes
/
HelloWorld.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package ie.dit; // Must be in the folder ie/dit
public class HelloWorld // public can be used outside the ie.dit package
{
// static method is a method that
// doesnt require an instance of the class to be calledf
public static void main(String[] args) {
System.out.println("Hello world"); // print stuff
// The TYPE is of the superclass
// The instance is of a subclass
Animal misty = new Dog(); // Polymorphism
// Calling a method
misty.setName("Misty");
// Calling a method and getting a return value
System.out.println(misty.getName());
misty.speak();
misty = new Cat();
misty.speak();
Cat garfield = new Cat();
garfield.setName("Garfield");
misty = garfield;
garfield.setName("Felix");
System.out.println(misty.getName());
while(garfield.getNumLives() > 0)
{
garfield.kill();
}
}
}