Interface and Abstract Classes
| Java Discuss, Interface and Abstract Classes at Programmers Lounge forum; Interface class
An interface class is simple, it requires another class to provide specific methods.
For example, the comparable interface ... |
| Notices | Welcome to the Gamerz Needs forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |  | 
08-23-2006, 09:39 AM
|  | Armenia | | | Last Online: Today 01:41 PM Join Date: Mar 2006 Location: Boss World :D
Posts: 2,671
Thanks: 225
Thanked 540 Times in 348 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 14 Points: 43,665.01 Bank: 499.61 Total Points: 44,164.62 | | Interface and Abstract Classes Interface class An interface class is simple, it requires another class to provide specific methods. For example, the comparable interface makes you provide a compareTo method. It provides classes to provide similiar behavior to other class that also implement a interface. So if you use foriegn class that implements comparable, you'll know that there is a compareTo method and it will be easy to figure the purpose of the class. Example public interface ClassInterface
{
void methodNameOne();
int methodNameTwo(int q);
}
public class ClassName implements ClassInterface
{
public void methodNameOne()
{
System.out.println("This is method one");
}
public int methodNameTwo(int q)
{
return 5+q;
}
} Note: All methods in a interface are public. Abstract An abstract class is really the mixture of an extension class and a interface. To learn more about extending class click here. Abstract classes have methods that it requires other classes to use, and it can provide methods for a class like extending it. You can of override the method in the class that uses the abstract class. Example public abstract class AbstractClass
{
public int number;
public AbstractClass(int theNumber)
{
number = theNumber;
}
public abstract void printSomething();
public void addFive()
{
number = number + 5;
}
}
public class ClassName extends AbstractClass
{
public int number;
public AbstractClass(int aNumber)
{
super(aNumber);
}
public abstract void printSomething()
{
System.out.println("q");
}
} Basically this is a class extension except for the printSomething method. This is more like the interface class because it requires you to provide the method. So a abstract class give you the best of extending classes and interfaces. You can require methods to provide methods even if you don't provide a base method in the abstract class (public abstract void printSomething() . It also lets you provide methods that the class that uses can access ( public AbstractClass(int theNumber) ). Remember, a class that uses 'extends' can only extend ONE class in java. Thank Me If You Liked It!!!! Credits go to Giraffaneckk!
__________________ | | The Following User Says Thank You to M0NK3Y For This Useful Post: | |  | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | |