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
What is return code?
What are the advantages of functions?
Does chrome use java?
What is the purpose of using java.lang.class class?
Difference between a class and an object?
Where import statement is used in a java program?
State the significance of public, private, protected class?
What is class??
How do you square a number in java?
Is java hard to learn?
Is break statement can be used as labels in java?
Can a class have an interface?
What is meant by method?
How to make object serializable in java?
Does java initialize arrays to zero?