मराठी

Explain the relation between a Class and an Interface?

Advertisements

प्रश्न

Explain the relation between a Class and an Interface?

स्पष्ट करा
Advertisements

उत्तर

In Java, a Class is a blueprint for creating objects, whereas an Interface is a reference type that defines a set of methods and constants. An interface specifies what operations must be performed, while a class provides their actual implementation.

  1. Implementation: A class implements an interface using the implements keyword and provides implementations for the abstract methods declared in the interface.
  2. Abstraction: An interface provides abstraction by specifying the required operations without defining how they are performed.
  3. Multiple Inheritance: A class can implement more than one interface, allowing it to follow multiple sets of method contracts.
  4. Method Declaration: An interface can declare abstract methods, whereas a class implementing the interface provides their definitions.
  5. Code Reusability: Interfaces promote code reusability, flexibility and better organisation by allowing different classes to follow a common structure.
  6. Relationship: An interface defines a contract that a class agrees to follow by implementing its required methods.
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 4: Objects - EXERCISE [पृष्ठ १०७]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
पाठ 4 Objects
EXERCISE | Q 10. (ii) | पृष्ठ १०७
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×