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


Please Help Members By Posting Answers For Below Questions

What is mysql driver class name?

550


These static constructors are correct ? class A { statc intA() { } static A(int x,int y) { } static A(int x) { } }

597


Can we create more than one object singleton class?

575


Can you override private or static method in java?

547


Can java inner class be static?

557






What is meant by attribute?

591


What are the features of junit?

598


What are the four integer types supported by java?

558


Make a data structure and implement an algorithm to print all the files in a directory. (The root directory can have sub-directories too.)

849


What is vector?

587


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

3188


What do you mean by access modifier?

552


Explain a few methods of overloading best practices in java?

504


How do you declare a variable?

621


Difference between default and protected access specifiers?

498