• Post Reply Bookmark Topic Watch Topic
  • New Topic

interface reference type  RSS feed

 
Raj chiru
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public interface ReportGenerator {
public void generate(String[][] table);
}



public class HtmlReportGenerator implements ReportGenerator {
public void generate(String[][] table) {
System.out.println("Generating HTML report ...");
}
}


public class PdfReportGenerator implements ReportGenerator {
public void generate(String[][] table) {
System.out.println("Generating PDF report ...");
}
}


public class ReportService {
private ReportGenerator reportGenerator = new PdfReportGenerator();
public void generateAnnualReport(int year) {
String[][] statistics = null;
//
// Gather statistics for the year ...
//
reportGenerator.generate(statistics);
}
public void generateMonthlyReport(int year, int month) {
String[][] statistics = null;
//
// Gather statistics for the month ...
//
reportGenerator.generate(statistics);
}
public void generateDailyReport(int year, int month, int day) {
String[][] statistics = null;
//
// Gather statistics for the day ...
//
reportGenerator.generate(statistics);
}
}

hi...,
My question is in preceding code we are use interface reference type i.e something like private ReportGenerator reportGenerator = new PdfReportGenerator(); in ReportService class. here my dought is when we call generate() method like reportGenerator.generate(statistics); whitch method is called (or executed)whether interface method or implementatiuon class method.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should be able to work that out for yourself. I'll give you a hint. An interface method is abstract (implicitly) and consists of a single ;
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!