• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interface is nothing but a pure abstract class. why interface does not has constructor
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Becasue constructors are used to initialize instances and interfaces cannot be instantiated.
 
ranjithkumar.gendhe kumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but abstract class has constructor. why
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

class file created only for class is it true?


Nope. Enums are also compiled to class files.
 
ranjithkumar.gendhe kumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 32
Eclipse IDE Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic