Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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().
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic