(Java)Interface

An interface is a collection of abstract methods. Aclass implements an interface, thereby inheriting the abstract methods of the interface.

An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements.

Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.

Example :
1. Create Class IntAyah

public  interface IntAyah{
	public void info(String n);
}
<pre> 

2. Create Class IntAnak

public class IntAnak implements IntAyah{
String nama;
public void info (String n){
	
	this.nama=n;
	System.out.println("Nama Anak:" + nama);

}
}
<pre> 

3. Create class TestInterface

class TestInterface{
public static void main(String []args){
	IntAnak ia = new IntAnak();
	ia.info("dede");
}
}
<pre> 

RESULT COMPILE

Nama Anak : dede

Reference :
– Ebook : Java Desktop Ifnu Bima
– Socket Java Programming STTA

Advertisements

Published by

jarcode

hello I am jarcode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s