Is it possible to do method overloading and overriding at a
time
Answers were Sorted based on User's Feedback
Yes, Is it possible to do method overloading and overriding at a
time
***********************************************
class A
{
void Add(int x, int y)
{
System.out.println("Hello From Class A" + (x+y));
}
}
class B extends A
{
void Add(int x, int y)
{
System.out.println("Hello From Class B" + (x+y));
}
void Add(double x, double y)
{
System.out.println("Hello From Class B" + (x+y));
}
}
class Test
{
public static void main(String ar[])
{
B acv = new B();
acv.Add(100.0,20.0);
acv.Add(10,20);
}
}
| Is This Answer Correct ? | 19 Yes | 0 No |
Answer / rameshreddy
No it is not possible at a time. Method overloading is
possible in the same class is possible. But method
overriding is possible its subclass only possible
| Is This Answer Correct ? | 18 Yes | 6 No |
Answer / sathishkumar.m
class A
{
int c;
void add()
{
System.out.println("hai");
}
void add(int b)
{
c=b;
System.out.println("value of b:"+c);
}
}
class B
{
int e;
void add(int d)
{
System.out.println("value of d:"+e);
}
}
class Demo
{
public static void main(String aa[])
{
A o1=new B();
o1.add();
}
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Explain purpose of sleep() method in java?
What are the different ways of implementing thread? Which one is more advantageous?
This is related to threads. I have a class with synchronized method m1(). Can I create different instances of this class and execute the m1() for different threads?
Define how destructors are defined in java?
what is the use of abstract class?
3 Answers Amdocs, Atos Origin, Invictus,
basic difference b/w ALL types of JDBC driver.
How do you find the independent variable?
How to create an immutable class?
What are the three parts of a lambda expression?
Can you make a constructor final?
Map map = new HashMap(2); map.add(“1”,”one”); map.add(“2”,”two”); map.add(“3”,”three”); What will happen at this line?
What is size of int in java?