Object creation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Object creation

If there is a super class named [Animal] and a child class named[Cat], then what is the difference between 1.Cat c=new Cat(); and 2.Animal c=new Cat() ; Pls explain.

26th Apr 2021, 3:35 AM
Jawahirullah
Jawahirullah - avatar
2 Answers
0
The first one is "INHERITANCE" and the second one shows the "POLYMORPHISM"
26th Apr 2021, 4:07 AM
sarada lakshmi
sarada lakshmi - avatar
0
if Cat has methods miau() and Animal not, in second way c can't use this method (without casting) public class Program { public static void main(String[] args) { Cat c=new Cat(); c.miau(); Animal a=new Cat(); //a.miau(); } } class Animal {} class Cat extends Animal { void miau(){} }
26th Apr 2021, 7:41 AM
zemiak