Professional Documents
Culture Documents
class Polygon {
public void display() {
System.out.println("Inside the Polygon class");
}
}
class AnonymousDemo {
public void createClass() {
class AnonymousDemo {
public void createClass() {
}
protected void finalize()// throws Throwable // finalize method is called on
object once before garbage collecting it
{
System.out.println("Garbage collector called");
System.out.println("Object garbage collected : " + this);
}
}
//NOTE : There is no guarantee that any one of above two methods will definitely
run Garbage Collector.
//The call System.gc() is effectively equivalent to the call :
Runtime.getRuntime().gc()
class local_nestedClass
{
public static void main(String[] args)
{
Outer_Class ot = new Outer_Class();
ot.display();
}
}
Member Inner Class
class Car {
String carName;
String carType;
// private method
private String getCarName() {
return this.carName;
}
// inner class
class Engine {
String engineType;
void setEngine() {
}else{
this.engineType = "Bigger";
}
}
String getEngineType(){
return this.engineType;
}
}
}
}
}