Do a basic matrix multiplication
A = [1 1 0 0]; B = [1; 2; 3; 4]; C = A*B C = 3
What is the difference between Inheritance and Polymorphism?
Polymorphism: Suppose you work for a company that sells pens. So you make a very nice class called "Pen" that handles everything that you need to know about a pen. You write all sorts of classes for billing, shipping, creating invoices, all using the Pen class. A day boss comes and says, "Great news! The company is growing and we are selling Books & CD's now!" Not great news because now you have to change every class that uses Pen to also use Book & CD. But what if you had originally created an interface called "SellableProduct", and Pen implemented this interface. Then you could have written all your shipping, invoicing, etc classes to use that interface instead of Pen. Now all you would have to do is create a new class called Book & CompactDisc which implements the SellableProduct interface. Because of polymorphism, all of the other classes could continue to work without change! Make Sense? So, it means using Inheritance which is one of the way to achieve polymorphism. Polymorphism can be possible in a class / interface but Inheritance always between 2 OR more classes / interfaces. Inheritance always conform "is-a" relationship whereas it is not always with Polymorphism (which can conform both "is-a" / "has-a" relationship.
What is the response for the following in Java and in C? int a = 3; int b = a; a = 5; b = ?
In C, b would have the value of 3. However, in Java, this same value would be 5. This is because Java uses reference pointers.