*Inheritance
-Is the capability of a class to use the properties and methods of another class while adding its own functionality. An example of where this could be useful is with an employee records system. You could create a generic employee class with states and actions that are common to all employees. Then more specific classes could be defined for salaried, commissioned and hourly employees. The generic class is known as the parent (or superclass or base class) and the specific classes as children (or subclasses or derived classes). The concept of inheritance greatly enhances the ability to reuse code as well as making design a much simpler and cleaner process.
>Super Class-
Any class above a specific class in the class hierarchy.
>Sub class
Any class below a specific class in the class hierarchy.
A subclass can also explicitly call a constructor of its immediate superclass. This is done by using the super constructor call. A super constructor call in the constructor of a subclass will result in the execution of relevant constructor from the superclass, based on the arguments pa
>Benefits of Inheritance
Benefits of Inheritance in OOP : Reusability– Once a behavior (method) is defined in a superclass, that behavior is automatically inherited by all subclasses. – Thus, you can encode a method only once and they can be used by all subclasses. – A subclass only needs to implement the differences between itself and the parent.
>Overriding Methods-
methods are methods that are redefined within an inherited or subclass. They have the same signature and the subclass definition is used.
If for some reason a derived class needs to have a different implementation of a certain method from that of the superclass, overriding methods could prove to be very useful. A subclass can override a method defined in its superclass by providing a new implementation for that method.
>Final Methods and Classes
Final Methods–
Methods that cannot be overridden
To declare final methods, we write,
public final [returnType] [methodName]([parameters]){. . .}
>Static methods are automatically final.
Final Classes
– Classes that cannot be extended
– To declare final classes, we write,
public final ClassName{. . . }
Example:
Other examples of final classes are your wrapper classes and Strings.
public final class Person { . . . }
*Polymorphism
– The ability of a reference variable to change behavior according to what object it is holding.– This allows multiple objects of different subclasses to be treated as objects of a single superclass, while automatically selecting the proper methods to apply to a particular object based on the subclass it belongs to.
Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. This is the third basic principle of object oriented programming. Overloading and overriding are two types of polymorphism . Now we will look at the third type: dynamic method binding.
>Abstract Classes
a class that cannot be instantiated. often appears at the top of an object-oriented programming class hierarchy, defining the broad types of actions possible with objects of all subclasses of the class.
*Interface
Interfaces are similar to abstract classes but all methods are abstract and all properties are static final. Interfaces can be inherited (ie. you can have a sub-interface). As with classes the extends keyword is used for inheritence.Java does not allow multiple inheritance for classes (ie. a subclass being the extension of more than one superclass). An interface is used to tie elements of several classes together. Interfaces are also used to separate design from coding as class method headers are specified but not their bodies. This allows compilation and parameter consistency testing prior to the coding phase. Interfaces are also used to set up unit testing frameworks.
-Is the capability of a class to use the properties and methods of another class while adding its own functionality. An example of where this could be useful is with an employee records system. You could create a generic employee class with states and actions that are common to all employees. Then more specific classes could be defined for salaried, commissioned and hourly employees. The generic class is known as the parent (or superclass or base class) and the specific classes as children (or subclasses or derived classes). The concept of inheritance greatly enhances the ability to reuse code as well as making design a much simpler and cleaner process.>Super Class-
Any class above a specific class in the class hierarchy.
>Sub class
Any class below a specific class in the class hierarchy.
A subclass can also explicitly call a constructor of its immediate superclass. This is done by using the super constructor call. A super constructor call in the constructor of a subclass will result in the execution of relevant constructor from the superclass, based on the arguments pa
>Benefits of Inheritance
Benefits of Inheritance in OOP : Reusability– Once a behavior (method) is defined in a superclass, that behavior is automatically inherited by all subclasses. – Thus, you can encode a method only once and they can be used by all subclasses. – A subclass only needs to implement the differences between itself and the parent.
>Overriding Methods-
methods are methods that are redefined within an inherited or subclass. They have the same signature and the subclass definition is used.
If for some reason a derived class needs to have a different implementation of a certain method from that of the superclass, overriding methods could prove to be very useful. A subclass can override a method defined in its superclass by providing a new implementation for that method.
>Final Methods and Classes
Final Methods–
Methods that cannot be overridden
To declare final methods, we write,
public final [returnType] [methodName]([parameters]){. . .}
>Static methods are automatically final.
Final Classes
– Classes that cannot be extended
– To declare final classes, we write,
public final ClassName{. . . }
Example:
Other examples of final classes are your wrapper classes and Strings.
public final class Person { . . . }
*Polymorphism

– The ability of a reference variable to change behavior according to what object it is holding.– This allows multiple objects of different subclasses to be treated as objects of a single superclass, while automatically selecting the proper methods to apply to a particular object based on the subclass it belongs to.
Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. This is the third basic principle of object oriented programming. Overloading and overriding are two types of polymorphism . Now we will look at the third type: dynamic method binding.
>Abstract Classes
a class that cannot be instantiated. often appears at the top of an object-oriented programming class hierarchy, defining the broad types of actions possible with objects of all subclasses of the class.
*Interface
Interfaces are similar to abstract classes but all methods are abstract and all properties are static final. Interfaces can be inherited (ie. you can have a sub-interface). As with classes the extends keyword is used for inheritence.Java does not allow multiple inheritance for classes (ie. a subclass being the extension of more than one superclass). An interface is used to tie elements of several classes together. Interfaces are also used to separate design from coding as class method headers are specified but not their bodies. This allows compilation and parameter consistency testing prior to the coding phase. Interfaces are also used to set up unit testing frameworks.

0 comments:
Post a Comment