class vs interface

Solutions on MaxInterview for class vs interface by the best coders in the world

showing results for - "class vs interface"
Marc
01 Feb 2018
1A class describes the attributes and behaviors of an object .
2An interface contains behaviors that a class implements. 
Daniela
22 Aug 2018
1A class can be instantiated by 
2creating its objects.
3An interface is
4never instantiated as the methods 
5declared inside an interface are abstract
6and does not perform any action, 
7  so there is no use of instantiating any
8interface.
9A class is declared using a keyword class. 
10In the same way, an interface is 
11created using a keyword interface.
12The members of a class can have 
13access modifier like public, private, protected.
14But the members of an interface
15are always public as they have to be accessed 
16by the classes implementing them.
17The methods inside a class are 
18  defined to perform an action on the fields
19declared in the class. 
20The methods inside an interface are purely abstract.
21A class can implement any number 
22of interfaces but can extend only one 
23super class.
24An interface can extend any number
25of interfaces but cannot implement any
26interface.
27A class has constructors defined inside
28it to get the variable initialized.
29But, an interface does not have any
30constructors as there are no fields 
31to be initialized. The fields of an
32interface are initialized 
33at the time of their declaration only.
similar questions
queries leading to this page
class vs interface