Abstract method

A

Ah Ming

Hi,

I am a beginner of Java programmer. There is a question about the
following program segment. Why class ABC must be defined as Abstract
when aMethod has int b?

interface DEF {
public void aMethod(int a);
}

Abstract class ABC implements DEF {
public void aMethod(int a, int b) {
}
}

Thanks!
 
T

Tjerk Wolterink

Ah said:
Hi,

I am a beginner of Java programmer. There is a question about the
following program segment. Why class ABC must be defined as Abstract
when aMethod has int b?

interface DEF {
public void aMethod(int a);
}

Abstract class ABC implements DEF {
public void aMethod(int a, int b) {
}
}

Thanks!


aMethod in class ABC is a different method than aMethod from DEF, because of the
differen arguments lengths.

So ABC.aMethod(int, int) does not override aMethod(int) from DEF.
But because ABC implements DEF it should implement the methods from interface DEF.
IT does not do that and the only way to allow that is to make ABC abstract.
When you extend ABC you should implement the DEF internface, so then you should
define aMethod(int)
 
G

George W. Cherry

Ah Ming said:
Hi,

I am a beginner of Java programmer. There is a question about the
following program segment. Why class ABC must be defined as Abstract
when aMethod has int b?

interface DEF {
public void aMethod(int a);
}

Abstract class ABC implements DEF {
public void aMethod(int a, int b) {
}
}

A class (e.g., ABC) which purports to implement an
interface (e.g., DEF) must implement all the interface's
methods--or it must declare itself abstract. DEF does
not implement

public void aMethod(int a);

ABC implements a different method

public void aMethod(int a, int b)

George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top