a sample about abstract class

first: the abstract class:


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public abstract class test {

//here is very important. so others could implement this method as they wish
protected abstract Object performTest(Object str);

//this is for another test. when the class has been instantiated, the method above must have been implemented. So others could call
public String callPerformTest (String str)
String s = (String)performTest(str);
System.out.println(“dudu for test: ” + s);
return s;



And then a tester class:


public class testTester {

* @param args

public static String work(String str)
System.out.println(“dudu for test: str = ” + str);
return “wu”;

public static void main(String[] args) {
// TODO Auto-generated method stub
test aTest = new test()
//When new the class, the abstract method should be implemented!
protected Object performTest(Object str)
return (String) work((String) str);

String str = (String)aTest.performTest(“dudu Test!!”);
System.out.println(“dudu for test: ” + str);


str = aTest.callPerformTest(” a new test”);




Fill in your details below or click an icon to log in:

WordPress.com 徽标

您正在使用您的 WordPress.com 账号评论。 注销 /  更改 )

Google photo

您正在使用您的 Google 账号评论。 注销 /  更改 )

Twitter picture

您正在使用您的 Twitter 账号评论。 注销 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 注销 /  更改 )

Connecting to %s

%d 博主赞过: