Question: Go through the code below. Find IF ANY OO design principles are violated and explain your answer. If you find a violation, how will you

Go through the code below. Find IF ANY OO design principles are violated and explain your answer. If you find a violation, how will you refactor the code to solve the violation ?
public class Shape1{ protected double side1; protected double side2; public Shape1(double side1, double side2){ this.side1= side1; this.side2= side2; } public void set_side1(double s){ this.side1= s; } public void set_side2(double s){ this.side2= s; } public double calculateArea(){ return side1*side2; } }public class Shape2 extends Shape1{ public Shape2(double s){ super(s, s); } public void set_side1(double s){ this.side1= s; this.side2= s; } public void set_side2(double s){ this.side1= s; this.side2= s; } } public class Test { public static void main(String args[]) throws Exception { Shape1 shp = new Shape2(5); shp.set_side1(6); shp.set_side2(3); System.out.println(shp.calculateArea()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!