public class Solution {
public static void main(String[] args) {
Cat cat = new TomCat();
TomCat cat2 = new TomCat();
}
interface CanMove {
}
static class Cat implements CanMove {
}
static class TomCat extends Cat {
}
}
I want to know how different between cat1 and cat2 form this code. I think cat1 is cat2 , or cat2 is cat1. they are same. Please help explain to me (I truly understand or I mistake)How Different between These Object
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Robird
20 August 2021, 19:35
Difference is that you can write some method in Tomcat class and use it in cat2, in cat you are restricted to CanMove and Cat . if you have method run() in Tomcat class , you can use cat2.run(); but you cant cat.run() ,
if you want do that cat.run(), you will have to cast cat to Tomcat : (Tomcat)cat.run()
+1
Khongpak Phupkdee
21 August 2021, 01:54
Thank you very much 😍🥰
0