-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverrideRule3.java
More file actions
39 lines (32 loc) · 898 Bytes
/
Copy pathOverrideRule3.java
File metadata and controls
39 lines (32 loc) · 898 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
/* Overriding Rule 3->
* Return type of overridden method in child class can be different as that of parent, if it is
* "Co-variant return type" ( Is-A relationship between the return type)
*/
//Example->
class Interest
{
}
class InterestPersonalLoan extends Interest
{
}
class Loan
{
public Interest disp()
{
Interest it=new Interest();
return it;
}
}
class PersonalLoan extends Loan
{
public InterestPersonalLoan disp()//here we will not get any error even the return type id different that confilt the Rule 2.
{ //But here there is a Is-A relation b/w both the return type ( InterestPersonalLoan extends the Interest) so this is allowed.
InterestPersonalLoan ipl=new InterestPersonalLoan();
return ipl;
}
}
public class OverrideRule3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}