Page 400 - CITS - Computer Software Application -TT
P. 400

COMPUTER SOFTWARE APPLICATION - CITS




           Code Reusability
           Using an abstract class in the code saves time. We can call the abstract method wherever the method is necessary.
           Abstract class avoids the process of writing the same code again.
           Abstraction
           Data abstraction in Java helps the developers hide the code complications from the end-user by reducing the
           project’s complete characteristics to only the necessary components.
           Dynamic Resolution
           Using the support of dynamic method resolution, developers can solve multiple problems with the help of one
           abstract method.

           Before moving forward, let’s first understand how to declare an abstract class.


            Java Interfaces and their advantages

           An interface in Java is a blueprint of a class. It has static constants and abstract methods.

           The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java
           interface, not method body. It is used to achieve abstraction and multiple inheritance in Java.
           In other words, you can say that interfaces can have abstract methods and variables. It cannot have a method
           body.
           Java Interface also represents the IS-A relationship
           It cannot be instantiated just like the abstract class.
           Since Java 8, we can have default and static methods in an interface.

           Since Java 9, we can have private methods in an interface.

            Method Overriding in Java


           If subclass (child class) has the same method as declared in the parent class, it is known as method overriding
           in Java.
           In other words, If a subclass provides the specific implementation of the method that has been declared by one
           of its parent class, it is known as method overriding.
           Usage of Java Method Overriding
           •  Method overriding is used to provide the specific implementation of a method which is already provided by its
              superclass.
           •  Method overriding is used for runtime polymorphism
           Rules for Java Method Overriding
           1  The method must have the same name as in the parent class

           2  The method must have the same parameter as in the parent class.
           3  There must be an IS-A relationship (inheritance).
















                                                           387

 CITS : IT&ITES - Computer Software Application - Lesson 109 - 115  CITS : IT&ITES - Computer Software Application - Lesson 109 - 115
   395   396   397   398   399   400   401   402   403   404   405