ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
   
 
Categories  >>  Software  >>  Java Related  >>  Java J2EE  >>  Core Java
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
Hi Friends..


can any one provide the real time example for 
methodoverloading and methodoverriding .........
 Question Submitted By :: Narendher Sharma
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Hi Friends.. can any one provide the real time example for methodoverloading and methodoverriding .........
Answer
# 1
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
Aravind
 
  Re: Hi Friends.. can any one provide the real time example for methodoverloading and methodoverriding .........
Answer
# 2
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
Sivadasan
 
 
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Why are the methods of the Math class are static?  1
what is struts-config-xml?and its use?  3
What is an Applet ?  2
What is the ResourceBundle? Elementus-Technologies2
class A { class B { psvm(String args[]) { } } } if the prg saved in A.java whats the o/p? HCL6
how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion SAP-Labs2
what is difference between abstract and interface? can i give real time example for the two topics?  7
what is object type casting? give some example with related? HP2
Name the methods in mouse listeners ?  4
What is the difference between Object and Instance? TCS5
Map map = new HashMap(2); map.add(“1”,”one”); map.add(“2”,”two”); map.add(“3”,”three”); What will happen at this line? Rolta5
waht happens when a return type ,even void is specified for a constructor?  11
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2012  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com