• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface

 
Ritesh raushan
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


thanks....
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well ask youself

How can i create an object with incomplete blueprint??

 
Junilu Lacar
Bartender
Pie
Posts: 7306
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 7306
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k..but why we create reference variable of interface or abstract class...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic