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 ...


Go Back   Gamerz Needs - For All Your Gaming Needs! > Technology Zone > Programmers Lounge > Java
Forgot Password? | Sign Up!

Notices

Advertisement
   

Closed Thread
 
Bookmark this Thread Tools Display Modes
  #1  
Old 08-23-2006, 09:39 AM
M0NK3Y's Avatar
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
M0NK3Y will become famous soon enough
Points: 43,665.01
Bank: 499.61
Total Points: 44,164.62
Banana *yey* i <3 banana milkshake - Demonite cuz you back again lol - GameLordquest wanne do it again? xD - DeathniteR AYE AYE PIRATE! DRINK YOUR BEERZ! - M0NK3Y Im a M0NK3Y Pirate so.. i need a banana! :D - M0NK3Y 
No Message - M0NK3Y No Message - M0NK3Y No Message - M0NK3Y No Message - M0NK3Y 
Black - Andrex2x Burgundy - Demonite Black - Demonite Burgundy - Demonite 
Send a message via ICQ to M0NK3Y Send a message via AIM to M0NK3Y Send a message via MSN to M0NK3Y Send a message via Yahoo to M0NK3Y
Exclamation 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:
dragoon (08-23-2006)
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Advertisement
   


Main Navigation
Home
GzN Forums
GzN Games
GzN News
Top Games
GzN Cheats
GzN Articles
GzN Reviews
GzN Downloads
User Control Panel
Advertising
RSS Feed
2Moons
Adventure Quest
AirRivals
America's Army
Anarchy Online
Archlord
Audition
Battlefield Series
Cabal Online
Call Of Duty Series
Combat Arms
Conquer Online
Counter Strike
Day of Defeat
Deicide Online
Diablo Series
Doom Series
Drift City
Enemy Territory
Eudemons Online
Final Fantasy
Flyff (Fly For Fun)
General Game Discussion
Ghost Online
Granado Espada
Grand Theft Auto Series
Guild Wars
Gunbound
Gunz Online
Habbo Hotel
Half-Life 2
Hero Online
KartRider
Knights Online
Maple Story
Medal of Honor
MU Online
Neopets
Pangya
Quake Series
Ragnarok Online
Rappelz
Rakion
Red Orchestra
Rose Online
Runescape
Scions of Fate
Silkroad Online
Sims Series
Soldier Front
Starcraft
Tales of Pirates
Tibia
The Ship
Trickster Online
TS Online
Unreal Tournament
War Rock
WolfTeam
World of Warcraft & Series
Affiliates
COD4 Hacks
BF2 Hacks


All times are GMT -8. The time now is 03:51 PM.