Static Imports - Abstract Class - Interface - Is
Static Imports - Abstract Class - Interface - Is
Sample Program:
Note:
1. if class/method is abstract, it should be written in italics in UML Diagram
Java Interfaces
➢ An interface is a completely "abstract class" that is used to group related methods with
empty bodies.
➢ A Java Interface is a contract between the client code and the class that implements
that interface.
Notes on Interfaces
➢ Like abstract classes, interfaces cannot be used to create objects.
➢ Interface methods do not have a body - the body is provided by the implementing
class.
➢ To access the interface methods, the interface must be "implemented" (kind of
inherited) by another class with the implements keyword (instead of extends).
➢ Interface methods are by default abstract and public.
➢ All methods in the interface should be overridden by the implementing class.
➢ Interface attributes are by default public, static and final.
➢ An interface cannot contain a constructor (as it cannot be used to create objects)
➢ Java Interface also represents the IS-A relationship.
➢ Implementing multiple interfaces is Java’s way of implementing multiple
inheritance.
Interface inheritance
➢ it is possible for a java interface to inherit from another java interface, just like
classes can inherit from other classes. You specify inheritance using the extends
keyword.
Sample codes: InterfaceMultiple , InterfaceInheritance, InterfaceShape
Self-Paced Activity
A. Formative MP
1. Create a Java program that will accept numeric inputs. Based on the number of inputs, the
program will decide what shape it is. (1 input – circle, 2 inputs – square or rectangle, 3 inputs
– triangle). The program will then display the shape type, details, perimeter, and area.
Validate your inputs. Use the OOP approach(please refer to the given UML Diagrams)
Filename: InterfaceShape