asked in Inheritance by (58.6k points)

1 Answer

The Liskov substitution principle is one of the five object-oriented design principles, collectively know as .This design principle is L of SOLID acronym. The Liskov substitution principle states that in an object oriented program if a function or method is expecting an object of base class then  it should work fine with a derived class object as well. If it cannot function properly with derived class object then the derived class is violating the Liskov Substitution principle.

For example, if a method is expecting a List you can also pass and it should work just fine because ArrayList and LinkedList both follow Liskov Substitution Principle, but the which is a subclass of java.util.Date in Java violates Liskov Substitution Principle because you cannot pass an object of java.sql.Date class to a method which is expecting an object of java.util.Date, Why? because all time-related method will throw java.lang.UnsupportedOperationException.


 

answered by (58.6k points)

Java Interview Questions and Answers 2018

>
...