Abstract class, Method overring ,final keyword
Abstract class, Method overring ,final keyword
In this example, Bike is an abstract class that contains only one abstract method run.
Its implementation is provided by the Honda class.
Mostly, we don't know about the implementation class (which is hidden to the end
user), and an object of the implementation class is provided by the factory method.
In this example, if you create the instance of Rectangle class, draw() method of
Rectangle class will be invoked.
File: TestAbstraction1.java
In this example, we have defined the run method in the subclass as defined in the
parent class but it has some specific implementation. The name and parameter of the
method are the same, and there is IS-A relationship between the classes, so there is
method overriding.
Output:
The java final keyword can be used in many context. Final can be:
1. variable
2. method
3. class
If you make any variable as final, you cannot change the value of final variable(It will be
constant).
There is a final variable speedlimit, we are going to change the value of this variable, but It can't
be changed because final variable once assigned a value can never be changed.
class Bike9{
void run(){
speedlimit=400;
obj.run();
}//end of class
class Bike{
honda.run();
honda.run();