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
Why do we create public static method in java?
Is java 11 paid version?
What is a dot notation?
What is the epoch date?
What is a predicate method?
What is purpose of keyword void?
How is it possible in java programming for two string objects with identical values not to be equal under the == operator?
What is the purpose class.forname method?
Can a method be static?
Can we write any code after throw statement?
What are classloaders?
What is a generic data type?
Can list contain null in java?
When do we use hashset over treeset?
What is a singleton class? Give a practical example of its usage.