- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can interfaces have constructors in Java?
No, interfaces can’t have constructors for the following reasons −
- All the members of an interface are abstract, and since a constructor cannot be abstract.
Still, if you try to write a constructor within an interface it will generate a compile time error.
Example
public interface InterfaceTest { InterfaceTest(){ } public abstract void display(); public abstract void show(); }
Error
C:\Sample>javac InterfaceTest.java InterfaceTest.java:2: error: <dentifier> expected public InterfaceTest(){ ^ 1 error
- Related Articles
- Can we have generic constructors in Java?
- Can interfaces have Static methods in Java?
- Can an anonymous class have constructors in Java?
- Can constructors be inherited in Java?
- Why interfaces don't have static initialization block when it can have static methods alone in java?
- Can we extend interfaces in Java? Explain?
- Can an interface in Java extend multiple interfaces?
- Can an interface extend multiple interfaces in Java?\n
- Interfaces in Java
- Can constructors be marked final, abstract or static in Java?
- Constructors in Java\n
- How can we use lambda expressions with functional interfaces in Java?
- Get all Constructors in Java
- What are constructors in Java?
- Functional Interfaces in Java Programming

Advertisements