-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimal.java
More file actions
46 lines (44 loc) · 1011 Bytes
/
Animal.java
File metadata and controls
46 lines (44 loc) · 1011 Bytes
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
38
39
40
41
42
43
44
45
46
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package oops;
/**
*
* @author sunilshetty
*/
//program for polymorphism
//ability of an object to take on many forms
public class Animal {
public void animalsound()
{
System.out.println("This how animal sounds");
}
}
class pig extends Animal
{
public void animalsound()
{
System.out.println("wee eee");
}
}
class dog extends Animal
{
public void animalsound()
{
System.out.println("bow bow");
}
}
class mymainclass
{
public static void main(String[]args)
{
Animal myAnimal=new Animal();
Animal myPig = new pig();
Animal myDog = new dog();
myAnimal.animalsound();
myPig.animalsound();
myDog.animalsound();
}
}