what is mean by overriding in which situation we wil use?
Answer Posted / vikas
Overriding means, In a derived class, if we include same
method name, with same number & types of parameters and
return type as a method already defined in the base class,
then the method is said to be Overridden.
base class:
class Circle {
protected double radius;
public double getArea() {
return Math.PI*radius*radius;
}//this method returns the area of the circle
}
derived class:
class Cylinder extends Circle {
protected double length;
public double getArea() { // method overriden here
return 2*super.getArea()+2*Math.PI*radius*length;
}//this method returns the cylinder surface area
}
| Is This Answer Correct ? | 7 Yes | 1 No |
Post New Answer View All Answers
How big is a pointer?
Where to store local variables?
Which package has light weight components in java programming?
What are the different types of inner classes?
What is a lambda expression ? What's its use ?
Differentiate between stringbuffer and stringbuilder in java.
Explain restrictions for using anonymous inner classes?
java program with complete 4 oops concepts implemented example
Is 0 an even number?
How many bits is a boolean?
Differentiate between nested and inner class in java.
What is the epoch date?
When can we say that threads are not lightweight process in java?
Which is fastest collection in java?
How you can force the garbage collection?