Variable in Interfaces and Extent Interface-2.Pptx-2
Variable in Interfaces and Extent Interface-2.Pptx-2
https://www.ue.edu.pk/
An interface is different from a class:
https://www.ue.edu.pk/
Defining an interface
https://www.ue.edu.pk/
Difference between class and interface.
https://www.ue.edu.pk/
Defining an Interface
• Here interface is a keyword and interface name is any valid
java variable.
• Syntax:
Interface interfaceName
{
Variable Declaration;
Methods Declaration;
}
https://www.ue.edu.pk/
Extending Interfaces
• An interface can extend another interface in the same way that a class can extend another
class. The extends keyword is used to extend an interface, and the child interface inherits the
methods of the parent interface.
• Syntax:
Interface name1 extends name2
{
Body of name 2
}
https://www.ue.edu.pk/
Implementing the interface
https://www.ue.edu.pk/
Implementing and Extending Interface in Java
• An interface can extend another interface in the same way that a class can extend another
class. The extends keyword is used to extend an interface, and the child interface inherits
the methods of the parent interface. The following Sports interface is extended by Hockey
and Football interfaces.
https://www.ue.edu.pk/