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 mysql driver class name?
These static constructors are correct ? class A { statc intA() { } static A(int x,int y) { } static A(int x) { } }
Can we create more than one object singleton class?
Can you override private or static method in java?
Can java inner class be static?
What is meant by attribute?
What are the features of junit?
What are the four integer types supported by java?
Make a data structure and implement an algorithm to print all the files in a directory. (The root directory can have sub-directories too.)
What is vector?
which is advanced deep technology in java launched by the sun microsystem??? The answer is very logical If u need correct answer mail me at priya_gupta@gmail.com
What do you mean by access modifier?
Explain a few methods of overloading best practices in java?
How do you declare a variable?
Difference between default and protected access specifiers?