Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I extend and implement same method from an abstract class and interface

 
Ravindra Suroju
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method with same signature (arguments & return type) in an abstract class and interface. I want to extend the abstract class and implement the interface in a single class. how can I do that.... please help

Code:

interface Acceptable {
public void accept ();
}

public abstract class AbstractAccept {
public abstract void accept (); // updated the code, forgot to add abstract first time
}

public class ConcreteAccept extends AbstractAccept implements Acceptable {
//// implementation code goes here
}
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far? What's your first guess?
 
Ravindra Suroju
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried to implement both the methods as a same method. as below but it is throwing a NoClassDefFoundError

Code: //
public class test extends AbstractAccept implements Acceptable {
public void accept(){
System.out.println("running Successfully");
}
public static void main (String[] args) {
(new test()).accept();
}
}
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags. Unformatted code/config/etc. is difficult to read. You can edit your post to include them using the button or re-post the question with proper formatting.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic