약간의 배경 :
가 포함 된 세 개의 클래스는 다음과 같습니다 Tester(main method)
, DNASequence(object)
그리고 ProteinDNA(subclass of DNASequence)
. 세 가지 모두 동일한 패키지에 있습니다.
의 생성자 ProteinDNA
는 객체 DNASequence
와 정수 를 받습니다.
public class ProteinDNA extends DNASequence{
public ProteinDNA(DNASequence dna, int startAt){ //this is the constructor
클래스 ProteinDNA
를 컴파일하면 생성자에서 오류가 발생합니다.
Eclipse의 오류는 다음과 같습니다.
"Implicit super constructor `DNASequence()` is undefined.
Must explicitly invoke another constructor"
jGrasp의 오류는 다음과 같습니다.
ProteinDNA.java:16: error:
constructor DNASequence in class DNASequence cannot be applied to given types;
public ProteinDNA(DNASequence dna, int startAt)^{
required: String
found: no arguments
reason: actual and formal argument lists differ in length"
내가 무엇을 잘못하고 있지? Tester 클래스 ProteinDNA
는 적절하게 구성된 DNASequence
.
Parent Class DNASequence has existing constructor with parameters. There 2 solutions for this.
1) 기본 무인 수 생성자를 DNA Sequence 클래스에 추가 할 수 있습니다.
2) 아래와 같이 부모 클래스 생성자를 호출하도록 자식 클래스 생성자를 수정합니다.
public ProteinDNA(DNASequence dna, int startAt){
super(....); // This should be the 1st line in constructor code, add parameters
as per parent constructor
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다