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 multithreading and its advantages?
What are namespaces in java?
What is java util?
What is the size of string?
Is there a sort function in java?
Explain when noclassdeffounderror will be raised ?
What is port number in java?
What do you mean by static variable?
What is the do while loop syntax?
Write a program in java to create a doubly linked list containing n nodes.
how can you take care of mutual exclusion using java threads? : Java thread
Can an abstract class be a final class?
what is interface in java? Explain
How to find the index of the largest number in an arraylist java?
Why stringbuilder is not thread safe in java?