@@ThinkXAcademy is this how we do it¿ interface Shape{ void area(); } Class Rectangle implements Shape{ int length; int breadth; Rectangle(int l,int b){ length =l, breadth=b; } @override void area(){ System.out.println(length*breadth); } } Class Square implements Shape{ int area; Square(int a){ area=a; } @override void area(){ System.out.println(area*area); } }
@@ThinkXAcademy Shape is an interface in my code and not a class. As per my understanding the two classes rectangle and square are loosely coupled and shape is an interface. Please correct me if I'm wrong
Very well explained.
Good Explanation with Visual
thanks😄like and share
Can you also please explain how will you solve the shape,circle,square and rectangle problem ¿
Great and clear explanation @ThinkX Academy
The answer to this lies in next video of this course i.e. Interface Segregation (hint: Encapsulate what varies)
@@ThinkXAcademy is this how we do it¿
interface Shape{
void area();
}
Class Rectangle implements Shape{
int length;
int breadth;
Rectangle(int l,int b){
length =l,
breadth=b;
}
@override
void area(){
System.out.println(length*breadth);
}
}
Class Square implements Shape{
int area;
Square(int a){
area=a;
}
@override
void area(){
System.out.println(area*area);
}
}
Correct now area() is not coupled with shape class and every subclass has its own implementation. This concept is loose coupling.
@@ThinkXAcademy Shape is an interface in my code and not a class.
As per my understanding the two classes rectangle and square are loosely coupled and shape is an interface.
Please correct me if I'm wrong
You can make shape a class then only inheritance is possible and create an interface calculateArea.
very good teaching approach🪅♥