Method Overloading
Method Overloading
================
It is the modifier applicable only for methods and class but not for variables.
Abstract Methods::
Even though we don't have implementation still we can declare a method with
abstract modifier.
That is abstract methods have only declaration but not implementation.
Hence abstract method declaration should compulsorily ends with semicolon.
Example
=======
public abstract void methodOne(); => valid
public abstract void methodOne(){} => Invalid
Child classes are responsible to provide implementation for parent class abstract
methods.
Example
=======
Vehicle.java
============
abstract class Vehicle{
public abstract int getNoOfWheels();
}
Bus.java
========
class Bus extends Vehicle{
public int getNoOfWheels(){return 7;}
}
Auto.java
=========
class Auto extends Vehicle{
public int getNoOfWheels(){return 3;}
}
Note:: Abstract methods never speaks about implementation whereas if any modifier
talks about
implementation then the modifier will be enemy to abstract and that is
always illegal
combination for methods.
Abstract class
===============
For any java class,if we dont want to create any object then such type of classes
are refered as
abstract class.
Instantitation of abstract class is not possible.
example::
abstract class Test{
public static void main(String... args){
Test t=new Test();//CE:instantion not possible
}
}
eg1::
class Parent{
public void methodOne();
}
eg2::
class Parent{
public abstract void methodOne(){}
}
eg3::
abstract class Parent{
public abstract void methodOne();
}
final classes cannot contain abstract methods whereas abstract class can contain
final methods.
Example
final class A{
public abstract void methodOne();//Invalid
}
abstract class A{
public final void methodOne(){...}//Valid
}
if the class is declared as strictfp, then all the concrete methods under that
class
if they perform floating point arithmetic opertion will give platform independant
results.