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 multithreading and its advantages?

577


What are namespaces in java?

527


What is java util?

541


What is the size of string?

566


Is there a sort function in java?

575






Explain when noclassdeffounderror will be raised ?

620


What is port number in java?

593


What do you mean by static variable?

578


What is the do while loop syntax?

553


Write a program in java to create a doubly linked list containing n nodes.

556


how can you take care of mutual exclusion using java threads? : Java thread

608


Can an abstract class be a final class?

531


what is interface in java? Explain

535


How to find the index of the largest number in an arraylist java?

519


Why stringbuilder is not thread safe in java?

574