Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

interface and abstract methods with the same name

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kindly consider the following code:-

interface Data {
public void load();
}
abstract class Info {
public abstract void load();
}

public class Employee extends Info implements Data {
public void load (){
System.out.println ("loading");
/*do something*/
}
}

This code compiles and runs fine. What if I need to implement two different load methods. One for the Data interface and the other for the abstract class Info?
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think, in that case how would you distinguish both methods that one
belongs to interface and one to class.
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raef Kandeel:
Kindly consider the following code:-

interface Data {
public void load();
}
abstract class Info {
public abstract void load();
}

public class Employee extends Info implements Data {
public void load (){
System.out.println ("loading");
/*do something*/
}
}

This code compiles and runs fine. What if I need to implement two different load methods. One for the Data interface and the other for the abstract class Info?



Why worry? because neither your interface nor your abstract class will do anything with the method. Interface will not provide body, you need to provide it. For abstract class, it will be inherited/overridden in sub-class.
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic