RSS2.0

Looking Something??



[Java] Simple Java Programming Language Keywords

Monday, March 3, 2008

Simple Java Keywords

a) new : Produce a single instans from a class dan make reference to that object.

Example :

class box {

int w,h,l;

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

public class BoxData {

public static void main(String[] args) {

box k = new box();

//k is a reference to an object of box class

}

}

b) private: Give a special access to a class so it can only be used by its class.

Example :

class box {

int w,h,l;

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

//w,h,and l variable can only be used by class Box

c) public : Give a special access to a class so it can be used by all classes.

Example :

class box {

int w,h,l;

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

//class box can be accessed by all classes include different package.

d) this : A special referenced symbol used in a method accessed by active object.

Example :

class box {

int w,h,l;

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

e) protected: Give a special access to a class so it can be used by a method which is in that class and subclass elements.

Example :

class box {

protected int w,h,l;

protected getW(){

return this.w;

}

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

0 comments: