public class Test extends Object{
public Test(){
}
protected void doSomething(){
}
protected Test dolt(){
return new Test();
}
}
public class Test2 extends Test {
public Test2(){
super();
super.doSomething();
}
public void doSomethingNew(){
}
public void doSomething(){
}
protected Test2 dolt(){
return new Test2();
}
}
public class Test3 {
public String toString(){
return "this is"+getClass().getName()+"class write is tostring() 方法";
}
public static void main(String[] args) {
System.out.println(new Test3());
}
}
public class Test4 {
}
public class Test5 {
public static void main(String[] args) {
String s1 = "123";
String s2 = "123";
System.out.println(s1.equals(s2));
Test4 v1 = new Test4();
Test4 v2 = new Test4();
System.out.println(v1.equals(v2));
}
}
public class Test6 {
public static void draw(Test7 test7) {
System.out.println("this is test6");
}
}
public class Test7 extends Test6{
public static void main(String[] args) {
Test7 test7 = new Test7();
draw(test7);
}
}
/**
* 重载
*/
public class Test8 {
public static int add(int a) {
return a;
}
public static int add(int a,int b) {
return a+b;
}
public static int add(int a,double b) {
return 1;
}
public static int add(int ...a) {
int len = a.length;
int s = 0;
for (int i = 0; i < len; i++) {
s += a[i];
}
return s;
}
public static void main(String[] args) {
System.out.println("add (int a)"+add(1));
System.out.println("add (int a,int b)"+add(1,2));
System.out.println("add (int a,double b)"+add(1,2.11));
System.out.println("add (int ...a)"+add(1,2,3,4,5,6));
}
}
/**
* 多态
*/
public class Test9 {
int num = 0;
public void draw(Test9 test9) {
System.out.println(num);
num++;
}
public static void main(String[] args) {
Test9 test9 = new Test9();
test9.draw(new Test10());
test9.draw(new Test11());
}
}
public class Test10 extends Test9{
public Test10(){
System.out.println("This is Test 10");
}
}
public class Test11 extends Test9 {
public Test11(){
System.out.println("This is Test11");
}
}
/**
* 接口
*/
interface Test12 {
public void draw();
}
public class Test13 {
public void doAnyThing(){
}
public static void main(String[] args) {
Test14 test14 = new Test14();
Test15 test15 = new Test15();
test14.draw();
test15.draw();
Test13 test13 = new Test13();
test13.doAnyThing();
}
}
public class Test14 extends Test13
implements Test12 {
public void draw(){
System.out.println("this is This14");
}
public void doAnyThing(){
}
}
public class Test15 extends Test13 implements Test12 {
public void draw(){
System.out.println("this is Test 15");
}
public void doAnyThing(){
}
}