wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interface" Watch "interface" New topic
Author

interface

Ritesh raushan
Ranch Hand

Joined: Aug 29, 2012
Posts: 100

why we don't create object of abstract class and interface.....


thanks....
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Because interfaces and abstract classes can have unimplemented methods. Their definition says the type in question provides those methods, but if we tried to call them, it wouldn't work.

The whole point of interfaces and abstract classes--the reason the exist--is to define a type that doesn't have a complete implementation and isn't meant to be directly instantiated.
Ankit Dan
Ranch Hand

Joined: Aug 31, 2012
Posts: 47

well ask youself

How can i create an object with incomplete blueprint??

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Jeff Verdegan wrote:The whole point of interfaces and abstract classes--the reason the exist--is to define a type that doesn't have a complete implementation and isn't meant to be directly instantiated.

I don't know if that's really "the whole point" or a consequence(?) -- IMO, the point of defining abstract classes and interfaces is abstraction -- you define a set of behaviors/capabilities without having to worry about the actual implementation; they specify a general contract for behavior or functionality to which all correctly implemented concretions must adhere.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Ankit Dan wrote:well ask youself
How can i create an object with incomplete blueprint??


I don't think this is quite right either. An abstract class or interface actually is a blueprint of sorts. What's missing is the concrete implementation. Maybe the correct question to ask is something like "Can you actually live in a blueprint?" And the answer is "No, you need the actual house that is built based on the blueprint." Some may argue that I'm quibbling over semantics but programming is very precise and correct semantics are a large part of that.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Junilu Lacar wrote:
Jeff Verdegan wrote:The whole point of interfaces and abstract classes--the reason the exist--is to define a type that doesn't have a complete implementation and isn't meant to be directly instantiated.

I don't know if that's really "the whole point" or a consequence(?)


Yeah, I guess the incomplete implementation is the whole point and the non-instantiability is a consequence.
Ritesh raushan
Ranch Hand

Joined: Aug 29, 2012
Posts: 100
k..but why we create reference variable of interface or abstract class...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Ritesh raushan wrote:k..but why we create reference variable of interface or abstract class...

SearchFirst . so that you will get more information
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Ritesh raushan wrote:k..but why we create reference variable of interface or abstract class...


Because, for example, we want a List, but we don't need to know or care if it's a LinkedList or ArrayList.

Or we want a JDBC Connection, but we don't need to know or care if it's a com.oracle.whatever.SomeConnection or a com.mysql.whatever.SomeOtherConnection.

Or we're writing a sort routine that takes a Comparable, but we don't need to know or care if it's an Integer or String or MyStudentClassThatIDefinedForMyJava101Homework. As long as it meets the contract of Comparable, we can sort it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interface
 
Similar Threads
How To Call Two Different Classes From the Main Program Using the Same API?
Home interface or Home Interface stub
Time Capsule
Writing an Interface
Regarding Interfaces