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(); }} "
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
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 ! .
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 ?