|Discuss the differences between creating a
new class, extending a class and implementing an interface and when each
would be appropriate.
*Creating a new class is simply creating a class with no extensions and no implementations. The signature is as follows
public class MyClass()
*Extending a class is when you want to use the functionality of another class or classes. The extended class inherits all of the functionality of the previous class.
An example of this when you create your own applet class and extend from
java.applet.Applet. This gives you all of the functionality of the java.applet.Applet class.
The signature would look like this
public class MyClass extends MyBaseClass
*Implementing an interface simply forces you to use the methods of the interface implemented. This gives you two advantages. This forces you to follow a standard (forces you to use certain methods) and in doing so gives you a channel for polymorphism.
This isnít the only way you can do polymorphism but this is one of the ways.
public class Fish implements Animal
Name four methods every Java class will have.
public String toString();
Do you have a Java Problem?
Return to : Java Programming Hints and Tips
All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.