aspose file tools*
The moose likes Beginning Java and the fly likes interface is nothing but a pure abstract class. why interface does not has constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interface is nothing but a pure abstract class. why interface does not has constructor" Watch "interface is nothing but a pure abstract class. why interface does not has constructor" New topic
Author

interface is nothing but a pure abstract class. why interface does not has constructor

ranjithkumar.gendhe kumar
Greenhorn

Joined: Oct 12, 2010
Posts: 19
interface is nothing but a pure abstract class. why interface does not has constructor
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

Becasue constructors are used to initialize instances and interfaces cannot be instantiated.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ranjithkumar.gendhe kumar
Greenhorn

Joined: Oct 12, 2010
Posts: 19
but abstract class has constructor. why
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

An abstract class is not an interface. It is a base class that can be extended by another class. As such it can be instantiated indirectly. Interfaces cannot.

Saying that "interface is nothing but a pure abstract class" is not correct. Though they may seem similar, they are not the same. A class can extend only one abstract base class, but can implement any number of interfaces.
ranjithkumar.gendhe kumar
Greenhorn

Joined: Oct 12, 2010
Posts: 19
could you just clarify this one


i created a java file. it contains only interface. when i compile this one it will create a class file.class file created only for class is it true?

Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
class file created only for class is it true?

Nope. Enums are also compiled to class files.
ranjithkumar.gendhe kumar
Greenhorn

Joined: Oct 12, 2010
Posts: 19
ya you are right it has constructor. but interface does not has constructor.

i created a file contains interface when compile this one compiler creates .class file to interface. what happening internally
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
You seem to see a connection between having a constructor and being a class file; that connection is spurious at best - better not to get attached to it.

I think the Java Virtual Machine specification, particularly chapter 4 "The class File Format" can help you. You may also wish to consult the Java Language Specification.
Kiaamaa Liammes
Ranch Hand

Joined: Oct 03, 2009
Posts: 32

when a class is compiled , it is converted into executable byte code , which is the .class file, on the other hand constructors are used to create instances i.e objects of a class


SCJP ,SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interface is nothing but a pure abstract class. why interface does not has constructor
 
Similar Threads
Abstarct class & Interfaces
Constructor
related to Abstract class
Interfave vs. Abstract
how abstract class constructor invokes while creating instance of Subclass