좋은 날 개발자.
그래서 문제가 있습니다.
내 클래스 가 메서드를 사용 MyClass
하여 인터페이스 IMyInterface
를 구현하고 메서드 doSomething();
를 재정의해야 doSomethiing()
합니다. 다른 클래스 TheOtherClass
도 IMyInterface
메서드를 구현 하고 재정의 doSomethiing()
하고이 doSomething()
메서드 (In TheOtherClass
) 의 일부 논리를 실현 합니다.
질문:
doSomething()
구현 된 메서드를 어떻게 만들 수 있습니까?MyClass
doSomething()
TheOtherClass
MyClass
호출 되면 doSomethig()
메서드가 자동으로 호출 되기를 원합니까 ??이런 것 같아요.
public class TheOtherClass implements IMyInterface{
public void doSomething(){}
}
public class MyClass implements IMyInterface{
// Instance initialization block:
// Runs before the constructor each time you instantiate an object
{
this.doSomething()
}
public MyClass(){
}
IMyInterface theOtherClass = new TheOtherClass ();
public void doSomething(){
theOtherClass .doSomething();
//Add more logic here
}
}
대신이 스레드에 따라 생성자에서 호출 해봐요의 링크 나 블록이 더 읽을 인스턴스 초기화를 사용하는 것이 좋습니다 여기를
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다