explain method overridding method overloding with examples?

Answers were Sorted based on User's Feedback



explain method overridding method overloding with examples?..

Answer / manoj jain

overriding and overloading both are type polymorphism.
overloading:-more then one functions or constructors have
same name but different signature is called overloading.
this is also called compile time polymorphism or static
polymorphism.

overriding:-method in child class has same name as in
parent class(function name and signature will be same in
parent and child class)that is called overriding.
child class method hides parent class method it is also
called bynamic binding or runtime polymprphism

Is This Answer Correct ?    11 Yes 0 No

explain method overridding method overloding with examples?..

Answer / muthusenthil

method overloading is to load some extra features in
existing method eg: a method takes string as an arguments
but overloaded method may take int along with String
trapPerson(String name)- pre-existing method
trapPerson(String name,int age)- overloaded method
(irrespective of return type)
this may take place in same class or derived clas

method overridding is to override a method from parentclass
to change its behaviour.name should be same as parentclass
method, behaviour may change
it should takes place between derived class
eg: class man extends superman
int walk() be one among characterstics of man overridden by
superman.

Is This Answer Correct ?    8 Yes 0 No

explain method overridding method overloding with examples?..

Answer / esha prasad

Overriding:: It's not any two classes will do to study this
scnario, because overriding will come in a scenario
involving parent child relationship.



public class Parent{

public void sum(int a, int b)
{
System.out.println(a+b);
}
class Child extends Parent
{


public void sum(int a, int b)
{
System.out.println("Sum of the integers = "+a+b);
}
}

}

class MainClass
{
public static void main(String[] args) {


}

}

Is This Answer Correct ?    8 Yes 0 No

explain method overridding method overloding with examples?..

Answer / zurreyab ahmad

Ovloding:in overloding case same method name and different
parameter and different return type
public class overlo {

public void add(int a, int b)
{
System.out.println(a+b);
}
public float add(float c, float d)
{
return c+d;
}
}

class main1
{
public static void main(String[] args) {


}

}
Overriding:: in overriding case the same method name and
same parameter and same return type and in overriding case
at least two class must have



public class overri {

public void add(int a, int b)
{
System.out.println(a+b);
}
class overri1
{


public void add(int a, int b)
{
System.out.println(a+b);
}
}}

class main1
{
public static void main(String[] args) {


}

}

Is This Answer Correct ?    7 Yes 1 No

explain method overridding method overloding with examples?..

Answer / senthamil kumaran

polymorphism can be divided into two tyes:-

Dynamic polymorphism or Run time polymorphism
Static polymorphism or Compile time polymorphism

Example for Static polymorphism
Method Overloading

Example for Dynamic polymorphism

Method Overriding



overloading: same method name but different argument list
is called as overloading

overriding:-same methodis redefined in the following
Derived classes with the same arugument list

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Struts Interview Questions

What are the core classes of struts?

0 Answers  


How can forward action be used to restrict a strut application to mvc?

0 Answers  


What is form bean in struts?

0 Answers  


what happen if the private constructor is written in a claass

6 Answers  


Hi frnds iam new to struts wen iam running helloworld application using struts iam getting the error as belwo kindly any one can solve it plzz .....thanks in advance......... Nov 18, 2009 9:27:46 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsExample1' did not find a matching property. Nov 18, 2009 9:27:46 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Struts1' did not find a matching property. Nov 18, 2009 9:27:46 PM org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\sys tem32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOW S\System32\Wbem;C:\Program Files\Java\jdk1.5.0_18\bin; Nov 18, 2009 9:27:46 PM org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on http-8081 Nov 18, 2009 9:27:46 PM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 678 ms Nov 18, 2009 9:27:46 PM org.apache.catalina.core.StandardService start INFO: Starting service Catalina Nov 18, 2009 9:27:46 PM org.apache.catalina.core.StandardEngine start INFO: Starting Servlet Engine: Apache Tomcat/6.0.20 Nov 18, 2009 9:27:46 PM org.apache.catalina.core.ApplicationContext log INFO: Marking servlet action as unavailable Nov 18, 2009 9:27:46 PM org.apache.catalina.core.ApplicationContext log SEVERE: Error loading WebappClassLoader delegate: false repositories: /WEB-INF/classes/ ----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader@ca2dce org.apache.struts.action.ActionServlet java.lang.ClassNotFoundException: org.apache.struts.action.ActionServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(Webap pClassLoader.java:1387) at org.apache.catalina.loader.WebappClassLoader.loadClass(Webap pClassLoader.java:1233) at org.apache.catalina.core.StandardWrapper.loadServlet(Standar dWrapper.java:1095) at org.apache.catalina.core.StandardWrapper.load(StandardWrappe r.java:993) at org.apache.catalina.core.StandardContext.loadOnStartup(Stand ardContext.java:4149) at org.apache.catalina.core.StandardContext.start(StandardConte xt.java:4458) at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1045) at org.apache.catalina.core.StandardHost.start(StandardHost.jav a:722) at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine .java:443) at org.apache.catalina.core.StandardService.start(StandardServi ce.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer .java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:583 ) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:2 88) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:41 3) Nov 18, 2009 9:27:46 PM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet /Struts1 threw load() exception java.lang.ClassNotFoundException: org.apache.struts.action.ActionServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(Webap pClassLoader.java:1387) at org.apache.catalina.loader.WebappClassLoader.loadClass(Webap pClassLoader.java:1233) at org.apache.catalina.core.StandardWrapper.loadServlet(Standar dWrapper.java:1095) at org.apache.catalina.core.StandardWrapper.load(StandardWrappe r.java:993) at org.apache.catalina.core.StandardContext.loadOnStartup(Stand ardContext.java:4149) at org.apache.catalina.core.StandardContext.start(StandardConte xt.java:4458) at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1045) at org.apache.catalina.core.StandardHost.start(StandardHost.jav a:722) at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine .java:443) at org.apache.catalina.core.StandardService.start(StandardServi ce.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer .java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:583 ) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:2 88) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:41 3) Nov 18, 2009 9:27:46 PM org.apache.coyote.http11.Http11Protocol start INFO: Starting Coyote HTTP/1.1 on http-8081 Nov 18, 2009 9:27:46 PM org.apache.jk.common.ChannelSocket init INFO: JK: ajp13 listening on /0.0.0.0:8009 Nov 18, 2009 9:27:46 PM org.apache.jk.server.JkMain start INFO: Jk running ID=0 time=0/31 config=null Nov 18, 2009 9:27:46 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 616 ms

2 Answers  






What is struts-default package and what are it’s benefits?

0 Answers  


Is struts efficient?

0 Answers  


How do you convert struts to springs?

0 Answers  


Why we use struts over servlets?

0 Answers  


How Struts will follow the MVC?

6 Answers   HCL,


what are the struts tags?

1 Answers  


What is dispatch action class?

0 Answers  


Categories