Kamis, 12 November 2009

innerclass, abstract & interface

1. Inner Class
public class Out
private String tacchi = “princetaro”;

class In{
String kaitaro = “princetako”;

public void talk(){
System.out.println(kaitaro);
System.out.println(tacchi);
}
}
}

class Test In{
publlic static void main (String args[]){
Out 1 = new Out();
Out.In d = 1.new In();
d.talk();
}
}

Output:
princetaro
princetako

2.Absract Class

abstract class Shape {
public String color;
}
public void setColor(String c) {
color = c;
}
public String getColor() {
return color;
}
abstract public double area();
}

public class Point extends Shape {

static int x, y;
public Point() {
x = 2;
y = 4;
}
public double area() {
return 0;
}
public double perimeter() {
return 0;
}
public static void print() {
System.out.println(“point: ” + x + “,” + y);
}
public static void main(String args[]) {
Point p = new Point();
p.print();
}
}

Output:
point: 2, 4

3.Interface dalam Java

class ImplementInterface implements
ContohInterface {
public void methodAbstrak1() {
System.out.println (“lalala″);
}
public void methodAbstrak2() {
System.out.println (“lilili″);
}
public void methodAbstrak3() {
System.out.println (“lololo″);
}
}

output:
lalala
lilili
lololo

0 komentar:

Posting Komentar