[英]how to override function of class while creating its object
我搜索了stackoverflow和Google,但听不懂。 这是我的代码。 Class Test和Class Tester在不同的程序包中,我无法扩展Test类
我想在Tester类的get()中重写class test的token()
public class Test{
private String d;
private String f;
Test(String d, String f) {
this. d = d;
this.f = f;
}
public String token(String a, String b) {
String c;
// token() logic
return c;
}
}
public class Tester{
public void get() {
Test t = new Test (“sample1”, “sample2”);
// get() logic
}
}
你这样子做
Test t = new Test("abc","xyz"){
@Override
public String token(String a, String b) {
// New logic here
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.