method overriding in java example
static method overriding in java
overriding equals method in java
overriding method in java
method overriding in java
example of method overriding in java method overloading in java rules rules for overriden method
Definition Of
Method Overriding :
Method overriding is equal to method heading is same but its signature
is different.
Or
The process of redefining the original method
in various ways for performing several operations is known as Method
Overriding.
The Following Rules must consider while doing with Method overriding or Overridden method:
1)
If we want to apply overriding we need to make use of inheritance concept.
2)
While we are overriding the methods, original
methods are always resides in
base class and overridden methods / redefined
methods always present in
derived class.
3)
Arguments of overridden
methods Must not change
4)
Return type of
overridden method Can't change except
for covariant (subtype) returns
5)
Exceptions can reduce/eliminate. Must not throw new/broader
checked exceptions
6)
Access must not be more
restrictive. Can be less restrictive.
7)
Invocation Which method to call is based on object type, at
runtime time
The Following Program
illustrate the concept of Method overriding
Class Basedemo
{
void fun1(int
x,int y)
{
System.out.println(“this is Base Demo”);
int z=x+y;
System.out.println(“sum in Base Demo is”+z);
}
}
Class InterBasedemo
extends Basedemo
{
void fun1(int
x,int y)
{
System.out.println(“this is Inter
Base Demo”);
int z=x*y;
System.out.println(“multiple in Inter
Base Demo is”+z);
}
}
Class Deriveddemo
extends InterBasedemo
{
void fun1(int
x,int y)
{
System.out.println(“this is Derived Demo”);
int z=x/y;
System.out.println(“division in Derived Demo is”+z);
}
}
Class Demo
{
public static void
main(String args[])
{
{
int x=Integer.ParseInt(args[0]);
int y=Integer.ParseInt(args[1]);
Demo do=new Demo();
Do.fun1(x,y);
}
}
No comments:
Post a Comment