• 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

Abstract Interface

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Courtesy of SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) (9780071591065)
Chapter 2, Exercise 1

Given:


public abstract interface Frobnicate {
public void twiddle(String s);
}


Which is a correct class? (Choose all that apply.)

A.

public abstract class Frob implements Frobnicate {
public abstract void twiddle(String s) { }
}

B.

public abstract class Frob implements Frobnicate { }

C.

public class Frob extends Frobnicate {
public void twiddle(Integer i) { }
}

D.

public class Frob implements Frobnicate {
public void twiddle(Integer i) { }
}

E.

public class Frob implements Frobnicate {
public void twiddle(String i) { }
public void twiddle(Integer s) { }
}


The answer to this is B and E
The book says answer is E because E is implementing the class in public void twiddle(String i) { } but the curly braces are empty so how is the class being implemented
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An interface is just a publication of some service... What that mean is that any class publishing that it supports such an interface must provide any implementation for that service as it sees fit...
In this context class E is publishing that it supports the interface but it does nothing...
 
Ranch Hand
Posts: 50
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When we give the curly braces, this means the method has a body. Even if there is no implementation code inside the body, it will be considered as valid implemented method. You can let the method do something by putting some code inside the body, leaving it just means method is not doing anything right now, may be in future you may add something.
 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right. Also note that an interface only declares that a concrete implementing class must provide an implementation for the methods itthe interface declares, but the interface says nothing about how a class must implement those methods.

Edit : Rico, I see that you have already said what I have said. 'Service', however, could be a difficult term to understand. Hence I considered adding on to your response. :-)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic