Interfaces
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Vallabhaneni Suresh Kumar:
Why do we create interfaces
Note the keyword interface instead of class
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Vallabhaneni Suresh Kumar:
Why do we create interfaces
Hello VS,
Well basically, interfaces are also sort of classes. But note : they are classes without any method bodies.
So basically, as u know that Java is an object oriented language, every real-world situation can be explained by objects.
To do so, we can decide to provide a basic skeleton of such a scenario which we wish 2 depict. The behavior of the skeletal model is defined by interfaces. That's why interfaces are used...to create the skeletal model.
Interfaces do not have method bodies. They simply have method prototypes which can be implemented by different classes to depict different behaviors of the same skeleton.
Hope u get it...
<strong><br />Cheers !!<br /> <br />Sherry<br /></strong><br />[SCJP 1.4]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Sherry Jacob:
Hello VS,
Well basically, interfaces are also sort of classes. But note : they are classes without any method bodies.
So basically, as u know that Java is an object oriented language, every real-world situation can be explained by objects.
To do so, we can decide to provide a basic skeleton of such a scenario which we wish 2 depict. The behavior of the skeletal model is defined by interfaces. That's why interfaces are used...to create the skeletal model.
Interfaces do not have method bodies. They simply have method prototypes which can be implemented by different classes to depict different behaviors of the same skeleton.
Hope u get it...
Whooops, I should read more carefully, I read how, not why
Sorry Vallabhaneni, Sherry's got you covered though
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Say I write a method that takes a List as a parameter. You can call my method with any object that implmements the List interface. I ignore the details about exactly what kind of object it is and focus on the detail that it can do List operations.
A class can implement more than one interface. So you could take almost any class, add "implements List" to its declaration, implement the list methods and pass it to my method. This gives you a lot of freedom. Your object doesn't have to be just one thing - the type it extends. It can implement several interfaces.
In more advanced designs we also use interfaces to control dependencies. (Dependency meaning we have to know all about something just to compile.) For example, Sun "owns" the JDBC interfaces and the various database vendors have to implement them. We depend on stable Sun APIs, and we don't depend on individual database vendors.
Powerful stuff, no? Keep asking questions!
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
| Climb the rope! CLIMB THE ROPE! You too tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |







