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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is interface can't implement anything? and can it extends so many classes at one time? this is the basic question which i am not knowing can anybody tell me? thanks
 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The interface just defines a template or skeleton and any class that implements that interface has to provide implementation for all methods defined in it.
Java does not support multiple inheritance. So extending more than one classes is not possible. Therefore the concept of interface aided, as the class can implement any no. of interfaces
Hope thsi helps to clear ur basics!
Rashmi
 
ronak mehta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rashmi Gunjotikar:

The interface just defines a template or skeleton and any class that implements that interface has to provide implementation for all methods defined in it.
Java does not support multiple inheritance. So extending more than one classes is not possible. Therefore the concept of interface aided, as the class can implement any no. of interfaces
Hope thsi helps to clear ur basics!
Rashmi


 
ronak mehta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know whatever you say and thanks for your reply. but in one exam they say that interface can't implement anything? is it true?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ronak,
yes this is true, an interface can't IMPLEMENT anything, but can extend other interface...
Only classes are capable of IMPLEMENTING something, interfaces are not. Be aware of the terminology, this is a very important issue in Java. Do not mix implements and extends...
Hope this helps,
VAl
 
ronak mehta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,
now is it possible that interface extends more than one class?
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again be aware of the terminology you use...
An interface cannot EXTEND classes.... An interface may extend other interfaces but not classes... And yes an interface may extend many other interfaces, the following code is valid
public interface I1 {}
public interface I2 {}
public interface I3 extends I1,I2 {}
Val
 
ronak mehta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

thanks.now i am clear thank you very much
ronak
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic