Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

interface and abstract methods with the same name

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic