Hi Friends..


can any one provide the real time example for
methodoverloading and methodoverriding .........

Answers were Sorted based on User's Feedback



Hi Friends.. can any one provide the real time example for methodoverloading and methodoverri..

Answer / sivadasan

Hi Here is the Example for Method Overloading:

class A{
  public void fun1(int x){
    System.out.println("The value of class A is : " + x);
  }
  public void fun1(int x,int y){
    System.out.println("The value of class B is : " + x + "
and " + y);
  }
}
public class polyone{
  public static void main(String[] args){
    A obj=new A();
// Here compiler decides that fun1(int)
is to be called and "int" will be printed.
    obj.fun1(2);   
// Here compiler decides that fun1(int,int)
is to be called and "int and int" will be printed. 
      obj.fun1(2,3);       
  }
}


And Method Overriding:

class A{
  public void fun1(int x){
     System.out.println("int in Class A is : "+ x);
  }
}

class B extends A{
  public void fun1(int x){
     System.out.println("int in Class B is : "+ x);
  }
}

public class polytwo{
  public static void main(String[] args){
     A obj;
     
     obj= new A(); // line 1
     obj.fun1(2);  // line 2 (prints "int in Class A is :
2")
     
     obj=new B();  // line 3
     obj.fun1(5);  // line 4 (prints ""int in Class B is :
5")


I think these are very very basic program example for
Method Overloading and Overriding...

Is This Answer Correct ?    3 Yes 1 No

Hi Friends.. can any one provide the real time example for methodoverloading and methodoverri..

Answer / aravind

Example Method:

public void method(int a)
{
....;
....;
}

Method Overloading:
class
{
method(140,1,10,250);
}

Method Overriding:
re implement same method in a class with same or additional
attributes.

method()
{
...;
}

Is This Answer Correct ?    0 Yes 8 No

Post New Answer

More Core Java Interview Questions

Define array. Tell me about 2-D array.

0 Answers   Agilent,


What is the significance of continue jump statement? Explain with an example.

0 Answers   Amdocs,


Write a program to calculate factorial in java?

0 Answers  


What is the properties class in java programming?

0 Answers  


Is zero a positive integer?

0 Answers  






Write a program to find the whether a number is an Armstrong number or not?

0 Answers   Aspire, Infogain,


What is null object in java?

0 Answers  


What is java in detail?

0 Answers  


Explain about narrowing conversion in java?

0 Answers  


What does those terms actually mean included in the j.d.k i.6?

0 Answers  


Can we have multiple public classes in a java source file?

0 Answers  


Can you make a constructor final?

0 Answers  


Categories