Wednesday, July 27, 2011

Palm Tree


package com.evs.objava33.class7;

import com.evs.objava33.class8.FirstInterface;

public class PalmTree extends Tree {
private int age;
private String breed;

private PalmTree(int age) {
super("DateTree");
this.age = age;
}

public PalmTree(int age, String breed) {
this(age);
this.breed = breed;
}

public String toString() {
return "PalmTree [age=" + age + ", breed=" + breed + "]";
}

public static void main(String[] args) {
PalmTree tree1 = new PalmTree(10, "Small");
DateTree tree2 = new DateTree(40, "tall");

// System.out.println(tree1);
// System.out.println(tree2);

Tree tree3 = new PalmTree(30, "Short");
System.out.println(tree3.getType());
Tree t5 = new PalmTree(23, "Dummy");
PalmTree t4 = (PalmTree) tree3;
// if (t5 instanceof PalmTree) {
if (t5.getClass() == PalmTree.class) {
t4 = (PalmTree) t5;
}

Tree[] trees = { tree1, tree2, tree3, t4, t5 };
FirstInterface[] ints = { tree1, tree2 };

for (FirstInterface t : ints) {
System.out.println(t.secndTime());
}

FirstInterface in = new FirstInterface() {
public long time() {
return 0;
}

public long secndTime() {
return 0;
}
};
System.out.println(in);
InnerFirstInterface ifi = tree1.new InnerFirstInterface();
System.out.println(ifi);
AnotherClass ac = new AnotherClass();

// Scope = Public, Private, Protected, Default
// Access = Default, Static

// Class Variable Method Constructor
// Public Y Y Y Y
// Private Y Y Y Y
// Protected Y Y Y Y
// Default Y Y Y Y

}

private interface AnotherInterface {
public void testing();
}

static class AnotherClass {
public int testing;
}

private class InnerFirstInterface implements FirstInterface {
public long time() {
return 0;
}

public long secndTime() {
return 0;
}
}

public long time() {
return System.currentTimeMillis();
}

public long secndTime() {
return time();
}
}

No comments:

Post a Comment