I have just come across Liskov Substitution Principle and casting during a lecture of (Java) Object-Oriented Programming. I understand what the principle states, that is, I can initialise a subclass with the type of a superclass:
SuperClass superClass = new SubClass();
My first concern regards the purpose of such operation. Why can't I just declare the subclass as usual (example follows)?
SubClass subClass = new SubClass();
Right after this, I got stuck on casting, as follows:
SuperClass superClass = new SubClass();
SubClass subClass = (SubClass)superClass;
Again, I struggle understanding the point of all of this.
Can anyone provide any clarification on the purpose of these procedures?