Page 468 - Computer science 868 Class 12
P. 468

•  In overloaded methods, best match is resolved using static binding.
              •  Static binding uses data type of variables to select which method will be invoked.

              If the method is matched with the right method definition by the compiler at run-time, it is called dynamic binding.
              Some features of dynamic binding are given below.

              •  Virtual methods use dynamic binding.
              •  The overriding methods are an example of dynamic binding.
              •  Dynamic binding uses object to resolve binding.

              12.3.2  Keyword Final
              The final keyword is a non-access modifier used for classes, attributes and methods, which makes their properties
              unalterable. The final keyword is used in following context:
              1.  A variable declared as final acts like a constant. The value of the variable cannot be changed. These variables are
                 generally written in uppercase using an underscore as a word separator.
              2.  A method declared with final keyword cannot be overridden.
              3.  A class declared with final keyword cannot be inherited. All wrapper classes like Integer, Float, Double, Short, etc.,
                 are final classes.


                  12.4 KEYWORD ABSTRACT
              We have already learnt about the OOP’s concept abstraction. Abstraction hides the background details and only the
              external interface is available to the user.

              The keyword abstract is a Java modifier which can be applied only to Java classes and methods. An abstract class or
              method starts with the keyword abstract.

              Abstract methods are the methods with only method declaration but no method body.

              The following are the properties of abstract method:
              •  Abstract methods have no method body.
              •  Abstract methods are present in abstract class only.

              •  Abstract methods are generally defined in base class. The implementation of the methods are done in the derived
                 class.
              •  An abstract method cannot be declared as final and will generate error message, if done so.

              The properties of an abstract class are given below.
              •  An abstract class must be declared with an abstract keyword.

              •  It can have abstract, non-abstract, static and final methods.
              •  It cannot be instantiated, that means we cannot create objects of abstract class type.
              •  Abstract class can have constructors.

              •  Generally, base classes are defined as an abstract class in inheritance. The implementation provided in derived class
                 methods overrides the abstract method of the base class.
              Let us explain or validate these properties with the help of some Java codes.








                466466  Touchpad Computer Science-XII
   463   464   465   466   467   468   469   470   471   472   473