ANONYMOUS CLASS ;

> Anonymous object ; Anonymous simply means nameless.

> An object which has no reference is known as an anonymous object.

> It can be used at the time of object creation only.

> If you have to use an object only once, an anonymous object is a good approach.

> It is an inner class without a name and for which only a single object is created.

PROGRAM ;

class Display {
public void display() {
System.out.println(“Inside the Polygon class”);
}
}



class AnonymousDemo {
public void createClass() {

// creation of anonymous class extending class Display


Display D1 = new Display () {
public void display() {
System.out.println(“Inside an anonymous class.”);
}
};
D1.display();
}
}



class Main {
public static void main(String[] args) {
AnonymousDemo an = new AnonymousDemo();
an.createClass();
}
}

ACCESS SPECIFIER ;

> There are four type of acces specifier ; below see the types.

> DEFAULT

> PUBLIC

> PRIVATE

> PROTECTED

DEFAULT ;

> When ever a specific access level is not specified, then it is assumed to be default.

> The scope of the default level is within the package.

PUBLIC ;

> This is the most common access level and whenever the public access specifier is used with an entity.

> that particular entity is accessible throughout from within or outside .

> the class, within or outside the package, etc.

PRIVATE ;

> When an entity is private, then this entity cannot be accessed outside the class.

> A private entity can only be accessible from within the class.

PROTECTED ;

> The protected access level has a scope that is within the package.

> A protected entity is also accessible outside the package through inherited class or child class.

MODIFIED THE ACCESS TABLES ;

Access(specifier) >Inside >Inside >outside >outside

Class packege packege packege

Subclass


Private Yes No No No


Default Yes Yes No No


Protected Yes Yes Yes No


Public Yes Yes Yes Yes

Leave a Comment