• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Basic  RSS feed

 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How to explain interface of an object?
 
Pratik D mehta
Ranch Hand
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its rather interface of a class .
Refer below
Interfaces
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't use thread titles like "Java Basic"
 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aman,

Interface are only used for implementing classes and hence forth we write it as follows


Suppose we have class Car and interface named Model

then we can write


Interface is a contract you can say to be more precise
 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am not asking about Interfaces in java, i am asking from general OOP point of view. A Class has an object and this object has some interface associated with it, which
tells that object what to do and how to do?
this is my point.
 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Campbell Ritchie
sorry and i shall take care from now on.
Thanks for suggestion.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface is a type of contract: a class that implements an interface must, at minimum, include implementations of the interface.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:An interface is a type of contract: a class that implements an interface must, at minimum, include implementations of the interface.


Just keep in mind what David said. Is a type of contract. When a concrete class implements it, it will must implement it's methods.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...
 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ok i got the point, Thank you Vishal Hegde, Pratik D mehta, David Newton, and Hebert Coelho for your valuable replies.
 
Harnoor Singh
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interface of the object is the method/methods through which it interacts with other objects or other part of program.
 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harnoor Singh wrote:Interface of the object is the method/methods through which it interacts with other objects or other part of program.


Absolutely this is what i was looking for, Thanks Harnoor Singh.

now my next question is that, is it right to say that we inherit interface of an object in inheritance and we do not inherit interface of an object in composition?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct: simply having a property that implements an interface doesn't mean the class now implements that same interface.

(It *can*, but in Java needs to be done manually, usually by delegating method calls to the property that implements the interface. Most IDEs can do this busy work automatically.)
 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Correct: simply having a property that implements an interface doesn't mean the class now implements that same interface.


:thumbup: thank you David
Regards
Aman
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!