what is mean by overriding in which situation we wil use?
Answers were Sorted based on User's Feedback
Answer / ramana
override methos have same method name with same
signature.which methods are apper in super class to sub
class.
Is This Answer Correct ? | 14 Yes | 2 No |
Answer / 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 |
According to J2ee Compleet reference java:
I Think the answer is that
Overriding means the : In inheritance If we Declare the
(Public of default) Method in the superclass Similarly we
declare the method with the same name ,Same type,same
number of parameters.but the Body of the method May
different When We Instansiate child class and access it
then child's method will called if u want to call super's
overriden method then use the [super()] method to access it
in child for this read [Java compleete reference's
Chapter#8] u will find reasonable answer
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / rishi
Whenever we use same mathod with the same signature that we
call mathod overloding and we use it, when we use
inharitence or abstract class.
Is This Answer Correct ? | 1 Yes | 2 No |
What happens if I remove static from main method?
What is the purpose of checked and unchecked exceptions in JAVA?
ublic class Java_Coding_Samples { public static void JavaHungr(NumberFormatException ae){ System.out.println("integer"); } public static void JavaHungry(Exception e){ System.out.println("string"); } public static void JavaHungry(ArithmeticException ae){ System.out.println("object"); } public static void main(String[] args) { JavaHungry(null); }
What is complexity in java?
What is extension method in java?
Why Java is not pure Object Oriented language?
Why webdriver is an interface?
How will you reverse a singly-link list?
0 Answers Akamai Technologies,
What is collection api?
What is the use of private static?
How do you read and print a string in java?
What is the difference between double and float variables in java?