-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLSP.java
More file actions
68 lines (61 loc) · 1.91 KB
/
LSP.java
File metadata and controls
68 lines (61 loc) · 1.91 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
package com.upGrad;
import com.sun.xml.internal.ws.api.model.CheckedException;
import com.sun.xml.internal.ws.model.CheckedExceptionImpl;
class Rectangle {
private int length;
private int breadth;
public int getLength(){
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getBreadth() {
return breadth;
}
public void setBreadth(int breadth) {
this.breadth = breadth;
}
public int getArea() {
return this.length * this.breadth;
}
}
class Square extends Rectangle {
public void setBreadth(int breadth) {
super.setBreadth(breadth);
super.setLength(breadth);
}
public void setLength(int length) {
super.setLength(length);
super.setBreadth(length);
}
}
public class LSP {
public void calculateArea(Rectangle r) {
r.setBreadth(2);
r.setLength(3);
if(r.getArea() != 6)
printError("area",r);
if(r.getBreadth() != 2)
printError("breadth",r);
if(r.getLength() != 3)
printError("breadth" , r);
}
private void printError(String errorIdentifer, Rectangle r) {
System.out.println("Unexpected value of " + errorIdentifer + " for instance of " + r.getClass().getName());
}
public static void main(String[] args)
{
printName5Times("Sandeep");
/*LSP lsp = new LSP();
// An instance of Rectangle is passed
lsp.calculateArea(new Rectangle());
// An instance of Square is passed
lsp.calculateArea(new Square());*/
}
public static void printName5Times(String name){
for(int i=0 ;i <=5 ;i ++){
System.out.println(i+ " " + "Print name : " + name );
}
}
}