• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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.
 
Good night. Drive safely. Here's a tiny ad for the road:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic