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 the exact difference in between Unicast and Multicast object? Where will it be used?
What is the purpose of the system class in java?
What is runtime locatable code?
You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain
Why for each loop is used?
What is the main difference between java platform and other platforms?
What are the types of collections in java?
What is nested interface?
What is temp in java?
What is meant by the value of a variable?
What is difference between path and classpath?
What is the inheritance?
what are synchronized methods and synchronized statements? : Java thread
Difference between java and javascript
What is a line break example?