Liskov Substitution Principle

Liskov Substitution Principle Explained:

Any reference variable attribute of Class that uses pointers to Parent Class must be fully replaceable with other Child objects of that same Parent Class.

public class LiskovPrinclple { 
   public static void main(String[] args) { 
      Shape shape = new Square(); 
   }
}

class Shape { }
class Square extends Shape {  }
class Circle extends Shape { }
class Triangle extends Shape { }

If you notice here, shape reference type can be assigned with Circle and Triangle object type easily.

Hope this clears your doubt.


One thought on “Liskov Substitution Principle

Comments are closed.