0

Sololearn Java Polymorphism 1 how do you recognize subcl

hi , how do you recognize subclasses & superclass when it is not obvioous as here ? Animal / Cat/ Dog : " class Animal { public void makeSound() { System.out.println("Grr..."); }} class Cat extends Animal { public void makeSound() { System.out.println("Meow"); }} class Dog extends Animal { public void makeSound() { System.out.println("Woof"); }} class Program { public static void main(String args[ ]) { Animal a = new Dog(); Animal b = new Cat(); Animal c= new Animal(); a.makeSound(); b.makeSound(); c.makeSound(); }} "

21st Apr 2019, 3:11 PM
S. Kaouche
S. Kaouche - avatar
6 Antworten
+ 1
I thought that it was possible thanks to the EXTEND keyword , was it ? class A () { ....}; class B extends A () {...} ; Now you know that A is superclass and B the subclass . am I right ? Otherwise we don't know . thanks Swim
21st Apr 2019, 5:54 PM
S. Kaouche
S. Kaouche - avatar
0
Thanks very much Swim for your fast answer , but my question was different . Maybe I ve asked it in a badly way ? how do we identify a subclass compared to a superclass ? How do you identify them ? They look the same ? Through the words Animal and Cat / Dog , yes ! it's easy but sometimes when you read codes , it's not obvious to make difference . So how do you make difference (when you read it !) between superclass & subclassses ? I don't see it , as for me . thanks Swimm and all for your help ! .
21st Apr 2019, 4:21 PM
S. Kaouche
S. Kaouche - avatar
0
yes exactly ! when it is not obvious with words themselves 1) ANIMAL 2) Cat / DOG ... With words it's easy to find what SUBclass and what is SUPERclass . But when it is class A , classB , class C , , how do you know where is sub and super class ? Do you see what I mean ?
21st Apr 2019, 6:55 PM
S. Kaouche
S. Kaouche - avatar