You are on page 1of 4

class Secret {

void display() {

}
}

public class Anonymous {


public static void main(String[] args) {
Secret c = new Secret() {
void display() {
System.out.println("This is a secret message");
}
};
c.display();
}
}

class Box implements Cloneable {


public Object clone() throws CloneNotSupportedException {
return (Box)super.clone();
}
int add(int a, int b) {
return a+b;
}
}

public class CloneObject {


public static void main(String args[]) throws CloneNotSupportedException {
Box b1 = new Box();
System.out.println("The addition is: "+b1.add(2, 3));
Box b2 = (Box) b1.clone();
System.out.println("The addition is: "+b2.add(2,3));
}
}
class RateInfo {
private double rate = 11.5/100;
public double amount = 1321.43;
public double term = 1.1;
class AskUser {
double interest() {
return rate*amount*term/100.0;
}
}
}

public class InterestRate {


public static void main(String[] args) {
RateInfo ri = new RateInfo();
RateInfo.AskUser a = ri.new AskUser();
System.out.println("The interest rate is: "+a.interest());
}
}

class LocalClass {
void getInfo() {
class Info {
void display() {
System.out.println("Hey there! From local inner class");
}
}
Info i = new Info();
i.display();
}
}
public class Local {
public static void main(String[] args) {
LocalClass lc = new LocalClass();
lc.getInfo();
}
}

class Name {
public static void main(String args[]) {
Integer i = new Integer(2);
System.out.println("The name of the integer class is: "+i.getClass().getName());
}
}

import MathPack.*;
class PackageMath {
public static void main(String args[]) {
addition a = new addition();
System.out.println("The addition of 2 numbers is: "+a.add(4,5));
subtraction s = new subtraction();
System.out.println("The subtraction of 2 numbers is: "+s.subtract(10, 5));
}
}
class MainClass {
private static int i = 10;
static class StaticNested {
void display() {
System.out.println("Hello World "+i);
}
}
}

public class StaticClass {


public static void main(String[] args) {
MainClass.StaticNested c = new MainClass.StaticNested();
c.display();
}
}

MathPack folder
-----------------------
package MathPack;
public class subtraction {
public int subtract(int i, int j) {
return i-j;
}
}

package MathPack;
public class addition {
public int add(int i, int j) {
return i+j;
}
}