[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

Java Programming Question about superclass

If we have a superclass called Animal which has a method called move(), and 2 subclasses Bird and Fish that extend from Animal. Bird has its own version of move() method which will have the movement of "fly". Fish has its version of move() method which execute "swim". If you create 2 objects:
Animal a1 = new Bird();
Animal a2 = new Fish();
What will happen when you call move() method using a1 with a1.move()? How about a2.move()?
0
bakerule22
Asked:
bakerule22
  • 4
  • 2
1 Solution
 
for_yanCommented:
It will use move() method of subclass
0
 
for_yanCommented:
so it will use jethods of Bird and Fiosh not animal
0
 
for_yanCommented:
This is called polymorphism
It will always execute method of the class as it was created in the new Command
even you call it animal but in its essesnce it is a Bird - so it will fly - very logical
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
bakerule22Author Commented:
ok thanks
0
 
for_yanCommented:

you can read it here :
http://download.oracle.com/javase/tutorial/java/IandI/polymorphism.html
or in many other places - this is a very important feature of Java inheritance mechanism
0
 
bakerule22Author Commented:
ok
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now