-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplementation of polymorphism by using arrays
More file actions
78 lines (65 loc) · 1.12 KB
/
implementation of polymorphism by using arrays
File metadata and controls
78 lines (65 loc) · 1.12 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.lang.*; //syatem library file
import java.lang.reflect.Array;
import java.io.*; //printstream classes
import java.util.*; //bcz of scanner class
import java.io.*;
class parasbhatt
{
void fn()
{
System.out.println("hey paras bhatt");
}
}
class paras extends parasbhatt
{
void fn()
{
System.out.println("hey paras");
}
}
class bhatt extends parasbhatt
{
void fn()
{
System.out.println("hey bhatt");
}
}
public class UdemyClasses
{
public static void main(String args[])
{
// int array[] = new int[3];
parasbhatt ref[] = new parasbhatt[3];
for(int i=0;i<ref.length;i++)
{
int option;
System.out.println("choose your option:");
Scanner take = new Scanner(System.in);
option = take.nextInt();
switch(option)
{
case 1:
ref[i] = new parasbhatt();
break;
case 2:
ref[i] = new paras();
break;
case 3:
ref[i] = new bhatt();
break;
case 4:
break;
}
if(option == 4)
{
System.out.println("EXIT");
break;
}
ref[i].fn();
}
for(int i=0;i<ref.length;i++)
{
ref[i].fn();
}
}
}