Tuesday, March 24, 2009

Core Java

Can we make a class as static?

We declare the top level class as the member of a package with the name of the class same as the java file. There is no point in making the top level class as static. It will be reported as an error by the java compiler.
The inner classes can how ever be declared as static.

The inner classes can be of four types:
1. Annonymous Inner class : The annonymous inner class is the class that does not have any name. It is created by calling the new() in the function argument. Like

Onclick.doAction(new xyz() {
public void actionPerformed()
{ }
});

So there is no way u can make the annonymous inner class as static.

2. Member classes: Member classes are the classes that are defined with in a class. They can be used any where with in the body of the same class. We can make the member classes as static. And we can access that class from outside by making use of the dot operator.

3. Nested Top Level classes: A nested top-level class is a member class with a static modifier. A nested top-level class is like any other top-level class except that it is declared within another class or interface. It is used to group a set of classes without creating any package.

4.Local Classes: Local classes are the classes which are are created and used inside a block.

No comments:

Post a Comment