• 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 doubt

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we say that interface extends from one or more interfaces. like interface A extends interface 8.

My question is that when class implements interface A than it become must for it to give body of methods in interface in it. but it is also must for this class to give body of method of interface B.

EXP:
INTERFACE B
{ method1();
method 2();
}

INTERFACE A extends INTERFACE B
{ method 3();
METHOD4();
}

CLASS C implements A
{METHOD 3()
{
}
METHOD4()
{
}
}

I WANT TO KNOW THAT IN THIS IMPLEMENTING CLASS I MUST HAVE TO GIVE BODY OF METOD1 AND METHOD 2 ALSO OR NOT? IF YES THAN WHY?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you're required to do so. Code will not compile otherwise.

An interface is a basically a contract, any implementing class should stick to the contract.

When interface BB extends interface B it's basically adding more requirements to the original contract in B.

So any class implementing BB must adhere to the new items in the contract, but also to the original ones.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you remove some of the shouting (ALL UPPERCASE) from your code, you could easily test this.

Consider that A inherits from B in your example. And any instance of C is also an instance of both A and B.
[ February 27, 2008: Message edited by: marc weber ]
 
pankaj goswami
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
now i got it

thanks allot for your quick replies.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All methods must be implementing in the class.
method1(),method2(),method3(),method4().
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic