-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopyArrayObjects.java
59 lines (56 loc) · 1.28 KB
/
CopyArrayObjects.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Faculty
{
private String name;
private String dept;
public String getName()
{
return name;
}
public Faculty(String name,String dept)
{
this.name=name;
this.dept=dept;
}
public String getDept()
{
return dept;
}
public String toString()
{
return "Faculty [name= "+name+", dept="+dept+"]";
}
}
class Hod extends Faculty
{
public Hod(String name,String dept)
{
super(name,dept);
}
public String toString()
{
return "Hod [name= "+getName()+", dept="+getDept()+"]";
}
}
public class CopyArrayObjects
{
public static <S extends T,T> void copy(S[] src,T[] tgt)
{
int i,limit;
limit=Math.min(src.length,tgt.length);
for(i=0;i<limit;i++)
{
tgt[i]=src[i];
}
}
public static void main(String args[])
{
Hod hod1=new Hod("johnny","cse");
Hod hod2=new Hod("ayush","cse");
Hod hod3=new Hod("rajan","cse");
Hod hod[]={hod1,hod2,hod3};
Faculty[] members=new Faculty[2];
CopyArrayObjects.copy(hod,members);
for(int i=0;i<members.length;i++)
{System.out.println(members[i]);}
}
}