Is Overloading possible in Sub class

In every book I found that Overloading means method with the same name and with different parameter define in same class.
But is possible if I define method with the same name and with different parameter in Sub class?
Like example given below :
public class OverLadingTest {
     public void test(int a, int b) {
          System.out.println("Inside test(int a, int b)");
     public static void main(String args[]){
               OverloadedSubclass overloadedSubclass = new OverloadedSubclass();
               overloadedSubclass.test(10.20,10.20);
class OverloadedSubclass extends OverLadingTest {
     public void test(double a, double b) {
          System.out.println("Inside test(double a, double b)");
Thanks in advance.

The nays have it!
package forums;
class Singularity
  public void test(int a) {
    System.out.println("Singularity.test(int a)");
class Universe extends Singularity
  @Override
  public void test(int a) {
    System.out.println("Universe.test(int a)");
  public void test(int a, int b) {
    System.out.println("Universe.test(int a, int b)");
public class OverloadingTest
  public static void main(String args[]) {
    Singularity s = new Universe();
    s.test(10);
    s.test(10, 20);
compile
C:\Java\home\src\forums>"C:\Program Files\Java\jdk1.6.0_12\bin\javac.exe" -Xlint -d C:\Java\home\classes -cp c:\java\home\src; C:\Java\home\src\forums\OverloadingTest.java
C:\Java\home\src\forums\OverloadingTest.java:27: test(int) in forums.Singularity cannot be applied to (int,int)
    s.test(10, 20);
     ^
1 errorI'd say that's pretty conclusive, wouldn't you? Go read up on Java's definition of a [method signature|http://java.sun.com/docs/books/tutorial/java/javaOO/methods.html]... It's not just the name, putz!
Cheers. Keith.

Similar Messages

  • Is it possible to OVERLOAD a super-class method in a sub-class?

    Hi all,
    I have a query that
    Is it possible to OVERLOAD a super-class method in a sub-class?
    If it is possible, please give me an example.
    Thanks,
    Hari

    Hi,
    Is the method int Display(int a){} overloading
    the super-class's void Display() method? If
    possible, please clarify this and how it would be
    method overloading?
    hanks,
    Hari
    Hi Hari,
    Yes, it is possible. Look at this piece of code:
    class Senior
         void Display()
              System.out.println("Super class method");
    class Junior extends Senior
         int Display(int a)
              System.out.println("Subclass method: "+a);
              return(a+10);
         }> }
    class example
         public static void main(String args[])
              Junior j = new Junior();
              j.Display();
    System.out.println("Subclass method
    od "+j.Display(5));
    Is this what you were asking? Hope this helped.Hi,
    I guess you guys are confused here...
    Overloading is achieved by methods in the same class...
    Overriding is across a superclass subclass methds.

  • Unable to implement Constructor Overloading in an inherited class. Plz Help

    Please do compile the program in in order to notice the error.
    class EmpDet
    int id,age;
    String name;
    String gender;
      EmpDet(int id1,String name1,int age1,String gender1)
        this.id = id1;
        this.name= name1;
        this.age= age1;
        this.gender = gender1;
       void Id_Name()
       System.out.println("EmpId : "+id+" and Name : "+name);
       void Gender_Age()
        System.out.println("Employee is a "+gender+" and is "+age+" years old.");
      class Employee extends EmpDet
           String locality;
        Employee(int a,String b,int c,String d)
             super(a,b,c,d);
        Employee(String locality1)// Constructor overloading. My problem.
             this.locality = locality1;
      void locality()
        System.out.println("The employee resides at "+locality);
       void DiplayStmt()
            System.out.println("DISPLAYING EMPLOYEE DETAILS..");
            System.out.println("******************************");
       public static void main (String[] args)
        Employee det = new Employee(010,"John",32,"M");
        Employee addr = new Employee("Tambaram");
        addr.DiplayStmt();
        det.Id_Name();
        det.Gender_Age();
        addr.locality();
      }

    Hey Thanks.. I guess what you said makes sense.
    I was fiding it hard to agree that there needs to be a match between the Constructors of the Base Class and the Sub Class. I altered the program by adding a constructor in the Base class and using the super(0 function in the Sub class and that seems to work..
    class EmpDet
    int id,age;
    String name;
    String gender;
    EmpDet(int id1,String name1,int age1,String gender1)
         this.id = id1;
    this.name= name1;
    this.age= age1;
    this.gender = gender1;
    EmpDet(String addr)
         System.out.println("Address is implemented in SubClass");
    void Id_Name()
    System.out.println("EmpId : "+id+" and Name : "+name);
    void Gender_Age()
    System.out.println("Employee is a "+gender+" and is "+age+" years old.");
    class Employee extends EmpDet
         String locality;
    Employee(int a,String b,int c,String d)
         super(a,b,c,d);
    Employee(String locality1) // Constructor Overloading
         super(locality1);
         this.locality = locality1;
    void locality()
    System.out.println("The employee resides at "+locality);
    void DiplayStmt()
         System.out.println("DISPLAYING EMPLOYEE DETAILS..");
         System.out.println("******************************");
    public static void main (String[] args)
    Employee det = new Employee(010,"John",32,"M");
    Employee addr = new Employee("Tambaram");
    addr.DiplayStmt();
    det.Id_Name();
    det.Gender_Age();
    addr.locality();
    Message was edited by:
    3402102

  • Can we chagne Super class method parameters in Sub class

    Hi,
    I created a super class.  In that class i created a method. That method is having 4 input parameters and 4 export parameters.
    I created a sub class for that super class. I need to use only 2 input parameters in this class rather than 4 parameters. I want to delete 2 Input parameters in the sub class of the super class method.  Is it possible.
    If possible. can we give an simple code or pseudo code?
    regards,
    krishna

    Hi,
    I think you can not.
    Because, only public attributes can be inherited and they will remain public in the subclass.
    for further detail check,
    http://help.sap.com/saphelp_nw70/helpdata/en/1d/df5f57127111d3b9390000e8353423/content.htm
    regards,
    Anirban

  • Can we change the Super class attribute scope in Sub class

    Hi.
    I created a super class. In that i have 4 attributes. That attributes are PUBLIC.
    I created a sub class. In that i got all super class attributes. I want to change that attributes as a Private. Is it possible.
    If it is possible.Give me an Example with code or Pseudo code.
    Regards.
    Krishna.

    Hi Krishna,
    It is not possible... If you declare the Attributes again in Subclass of the same name as that of Super class
    then the way of accessing them would be different from that of attributes in the main class.
    Hope this would help you
    Good luck
    Narin

  • Web Intelligence Sub Class Objects

    Hi Experts,
    By default, what data does the sub class object (blue object) display in a web intelligence document? Is it key, description etc. and is it possible to control what detailed object it displays as default. I know how to get the key and description from the detailed objects (green), but want to know what data the main object displays by default.
    I am asking because we've created a large web intelligence document with lots of formulas that contain [L03 Profit Center] = " [key]". The users want to maintain the hierarchy text, which if the objects display text as default will break our formula and cause lots of work to correct with the new [L03 Profit Center Key] object.
    Kind regards,
    Andrew

    Hi Andrew,
    I am not sure but I guess it depends on the Info-object setting at the BW level because I have seen both Descriptions and Key
    values being displayed from the Dimension (blue object).
    How-ever, you can change the definition of the object at the universe level and get the required value.
    Just check if you are getting the required values by default. If you are not getting the required value then just copy the Select
    clause of the L03 Profit Center Key and paste it in the Select clause of L03 Profit Center.
    Changing the definition of the object will save all your rework.
    Regards,
    Rohit

  • Sub classing Issue

    When subclass any object possible to do changes to the parent object and it automatically updated in the child object.
    But once do any changes in the child object it won't effect to the parent object (This is obvious according to the concept)
    But issue is from that point onwards, if do any changes to the parent object it wont effect to the child object.
    Same scenario applicable when do sub classing thro object group as well.
    Please clarify..
    Rgds
    shabar

    if do any changes to the parent object it wont effect to the child object.If you overwrite a property in the "child"-object, any changes at the "parent"-object on the same property will not be inherited any more. Changes on other property will still be inherited.

  • Sub-class objects changing lovu2019s in XI 3.0

    Hello all,
    I have a XI 3.0 universe where I have several classes and sub-classes like this;
    Class1
    ....Subclass1
    .............Object 1
    .............Object 2
    .............Object 3
    ....Subclass2
    .............Object 4
    .............Object 5
    .............Object 6
    ...Subclass3
    .............Object 7
    .............Object 8
    .............Object 9
    Class2
    ....Subclass1b
    .............Object 10
    .............Object 11
    .............Object 12
    While updating the objects lovu2019s (for sorting) in the properties window, Iu2019ve noticed that beginning with Object 4 that the lovu2019s are changing back to that of Object 1, this is also the case for Object 5 (changes to Object 2u2019s lov) all the way through Object 12. It seems that no mater how often I set and apply the sorted lov for all objects, they take on the settings of the objects in the first sub-class in my universe. When querys are ran from WebIntelligence, they display the correct SQL (and return no results as there is no data in my dev database as yet). Objects in other classes (not sub-classes) seem to be fine. Has anyone seen this type of behavior before?
    Iu2019m thinking that I will need to go to 3.1 and suspect this may be a bug, any thoughts or comments are appreciated....

    Hi Didier,
    I did copy some some of the objects from a subclass to another, and to make sure this was not the issue, I re-created new ones and had the same issue.  I was not aware that previous BOE versions (LOVs) had the issue though, which makes some sense. 
    At the moment, I'm suspecting this is a bug so I am asking the client to upgrade to 3.1 to see if the issue persist (I suspect it may), if so I will then open up a tech support case.
    Thanks, Joe Szabo

  • Java Sub-Classing Error.  Please Help!

    I am trying to understanding some classing sub-classing and the convertion exercise. The errors appear with the code at the bottom at compilation.
    HelloWorld.java:7: cannot resolve symbol
    symbol : method uniqueInSubSayHello()
    location: class SayHello
    sh2.uniqueInSubSayHello();
    ^
    HelloWorld.java:11: cannot resolve symbol
    symbol : method uniqueInSubSayHello()
    location: class SayHello
    sh2.uniqueInSubSayHello();
    ^
    class HelloWorld {
         public static void main (String args[]) {
              subSayHello subsh=new subSayHello();
              SayHello sh2=subsh;
              sh2.haha();
              sh2.uniqueInSubSayHello();
         int callUnique() {
              sh2.uniqueInSubSayHello();
    class SayHello {
         public SayHello() {
         public void haha() {
    class subSayHello extends SayHello {
         public subSayHello() {
         void uniqueInSubSayHello() {

    On line 7, sh2 points to an object of type SayHello (as you assigned two lines earlier) and therefore does not know about method UniqueUnSubSayHello.
    On line 11, sh2 has not been declared, since sh2 is not a variable declared globally within class SayHello. Therefore, it is not found.
    Best regards,
    Cemil

  • Exception in super and sub class

    when super class method throws an exception then sub class overridden method can throws child exception but when we talk about constructor why we throws parent class exception in derived class constructor????

    tcbhardwaj wrote:
         C() throws Throwable // why here parent of Exception class
         void ok() throws ArithmeticException // why here child of RunTimeException classFirst, you never need to declare a throws clause for unchecked exceptions--RuntimeException, Error, and their descendants.
    However, there are a couple of general rules for checked exceptions (such as IOException, SQLException, etc.). As you're studying these, keep in mind that a throws clause is a contract that promises what the method will not do. In particular, it doesn't promise that the method will throw those exceptions. It promises that it will not throw any other checked exceptions not covered by that throws clause.
    1. A child method that overrides a parent method cannot throw any checked exception outside what's covered by the parent's throws clause. So if the parent method declared throws IOException, the child cannot declare throws Exception, or throws SQLException, because both of those are outside the IOException "sub-hierarchy."
    2. A child method that overrides a parent method can declare to throw less than the parent throws. This is because, if the parent promises not to throw outside of some set, and the child promises not throw outside of a subset of that set, then clearly he's also not throwing outside of the parent's set. If the parent method declares throws SQLException, IOException, then the child can declare no exceptions at all, or just SQLException, or just IOException, or any combination of any of the subclasses of SQLE and IOE.
    Rules 1 and 2 do not apply in the case of constructors, because no constructor can ever override another constructor.
    3. When any method or constructor, A, invokes any other method or constructor, B, then any checked exception declared to be thrown by B must be either caught or declared to be thrown by A. If A catches or throws a parent of an exception thrown by B, then he's also implicitly catching or throwing the one that B mentions.

  • Do sub classes get their own copy of base class static members?

    Hi,
    I am sub classing a certain classwhich has a static member boolean used for status updating. I have two sub classes, each needing its own static copy of the boolean. Do they get their own copy, or must I redeclare the member in each sub class?
    AC

    You must re-declare them (hiding the superclass member) if you wish the subclass members to be "independent".
    class Coin {
        public static int FOO;
        public static int BAR;
    class Coin2 extends Coin {
        public static int BAR = 2;
        public static void main(String[] args) {
            FOO = 1;
            System.out.println("Coin FOO  = " + Coin.FOO);  // 1
            System.out.println("Coin2 FOO = " + Coin2.FOO); // 1
            System.out.println("Coin BAR  = " + Coin.BAR);  // 0
            System.out.println("Coin2 BAR = " + Coin2.BAR); // 2
    }HTH! :o)

  • Is it possible to refer class files by mapping network drive?

    Hi,
    Is it possible to refer class files from the server(By mapping network of client's server) and specify this in project setting. If yes, how?
    Right now I copied all class file needed, to 'myclasses' directory of jdevhome. this approach is working fine but the page is taking 20 to 30 minutes to refresh.
    What could be probable reason for taking this much time to refresh a page? what could be alternative for this?
    Will the mapping of drive and referring it will improve the performance?
    I am connected to server through VPN and using Window based JDeveloper.
    Regards,
    Adarsh

    Hi Adarsh,
    For the first part of your query, You can create a new Library in Project Settings to refer to the server classes.
    As for the performance issue, there could be many reasons. Do you really think class loading is the only reason for the same? You might want to check in the Log window as to which process is eating up your time before loading the page.
    ~Srinath.

  • Servicegen include sub class used by serviceClass

    I have AbstractWSBE class which will expose service to users, how can I include
    all other classs used by the AbstractWSBE webservice class using servicegen?
    should I use comma to list all other sub class with AbstractWSBE?
    <servicegen
    destEar="${ear_file}"
    warName="${war_file}">
    <service
    javaClassComponents="com.netsboss.WSBE.inf.AbstractWSBE"
    targetNamespace="${namespace}"
    serviceName="WSBE"
    serviceURI="/WSBE"
         generateTypes="True"
    expandMethods="True" >
    </service>
    </servicegen>

    The javaClassComponent specified in the servicegen cannot be
    abstract. At deploy time WS runtime need to create an instance
    of this class.
    http://manojc.com
    "Stephen Zeng" <[email protected]> wrote in message
    news:3edebe0a$[email protected]..
    >
    I have AbstractWSBE class which will expose service to users, how can Iinclude
    all other classs used by the AbstractWSBE webservice class usingservicegen?
    >
    should I use comma to list all other sub class with AbstractWSBE?
    <servicegen
    destEar="${ear_file}"
    warName="${war_file}">
    <service
    javaClassComponents="com.netsboss.WSBE.inf.AbstractWSBE"
    targetNamespace="${namespace}"
    serviceName="WSBE"
    serviceURI="/WSBE"
    generateTypes="True"
    expandMethods="True" >
    </service>
    </servicegen>

  • Servicegen for sub-class inside vector variable of Super

    java.lang.NoSuchMethodError
    at com.netsboss.WSBE.model.QueryItemCodec.typedInvokeGetter(QueryItemCod
    ec.java:87)
    at com.netsboss.WSBE.model.QueryItemCodec.invokeGetter(QueryItemCodec.ja
    va:56)
    at weblogic.xml.schema.binding.BeanCodecBase.gatherContents(BeanCodecBas
    e.java:295)
    at weblogic.xml.schema.binding.CodecBase.serializeFill(CodecBase.java:25
    3)
    at weblogic.xml.schema.binding.CodecBase.serialize(CodecBase.java:195)
    at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
    ls.java:184)loop
    at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
    ls.java:170)
    QueryItem {
    private Vector airItiners;
    public Vector getAirItiners() {
    return airItiners;
    public class AirItinerary implements Serializable{}
    QueryItem is my return class. The return result will include sub class AirItinerary
    in QueryItem's Vector. I notice servicegen will only generate stub and web.xml
    for QueryItem.
    I get above error, when the result return to client. How to generate necessary
    sub-class inside a vector variable of Super class?
    Stephen

    Hi Stephen,
    write my own ser/deser? Any other quick way?Our excellent support group ([email protected]) may be able to help with
    an alternative solution. If you could create a small reproducer, then
    this will help them with a clear picture of your goal.
    One more problem, wls deloy my WSBE.ear as a war correctly. But error show noDouble check the console log for any messages. Also try:
    http://[host]:[port]/[contextURI]/[serviceURI]
    See: http://edocs.bea.com/wls/docs70/webserv/client.html#1051033 and
    also check the console to verify the app is or is not deployed. See:
    http://edocs.bea.com/wls/docs70/programming/deploying.html
    HTHs,
    Bruce
    Stephen Zeng wrote:
    >
    Hi Bruce:
    Our company use wsl7.0. We are not able to update to wls8 in this project. Do
    I have to
    write my own ser/deser? Any other quick way?
    sub class variable:
    public class AirItinerary implements Serializable{
    private String air;
    private Vector flightItem; //sub class of AirItineray
    One more problem, wls deloy my WSBE.ear as a war correctly. But error show no
    deloyment found. web-services.xml has been generated by servicegen under web-inf
    path. Thanks Bruce.
    Stephen
    Bruce Stephens <[email protected]> wrote:
    Hi Stephen,
    The java.util.vector should be converted to a SOAP Array, see:
    http://edocs.bea.com/wls/docs81/webserv/assemble.html#1060696 however
    the issue of the sub-class is most likely the problem. Can you simplify
    the data types? You may just have to write your own ser/deser, see:
    http://edocs.bea.com/wls/docs81/webserv/customdata.html#1060764
    This is with WLS 8.1, right?
    Thanks,
    Bruce
    Stephen Zeng wrote:
    java.lang.NoSuchMethodError
    at com.netsboss.WSBE.model.QueryItemCodec.typedInvokeGetter(QueryItemCod
    ec.java:87)
    at com.netsboss.WSBE.model.QueryItemCodec.invokeGetter(QueryItemCodec.ja
    va:56)
    at weblogic.xml.schema.binding.BeanCodecBase.gatherContents(BeanCodecBas
    e.java:295)
    at weblogic.xml.schema.binding.CodecBase.serializeFill(CodecBase.java:25
    3)
    at weblogic.xml.schema.binding.CodecBase.serialize(CodecBase.java:195)
    at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
    ls.java:184)loop
    at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
    ls.java:170)
    QueryItem {
    private Vector airItiners;
    public Vector getAirItiners() {
    return airItiners;
    public class AirItinerary implements Serializable{}
    QueryItem is my return class. The return result will include sub classAirItinerary
    in QueryItem's Vector. I notice servicegen will only generate stuband web.xml
    for QueryItem.
    I get above error, when the result return to client. How to generatenecessary
    sub-class inside a vector variable of Super class?
    Stephen

  • Calling sub class method from superclass constructure

    hi all
    i have seen a program in which a super class constructure class methods of sub class before initialization of fields in subclass ,i want how this is posibble ?
    thanks in advance

    Hear is the code n other thing i have used final variable without initialization n compiler dosen't report error
    abstract class Test
    public Test()
    System.out.println("In DemoClass Constructer");
    this.show();
    public void show()
    System.out.println("In DemoClass Show() method");
    class Sub1 extends Test
    private final float number;
    public Sub1(float n)
    this.number=n;
    System.out.println((new StringBuilder()).append("Number is==").append(number).toString());
    int j;
    public void show()
    System.out.println("In Sub1 Class Show method ");
    public class DemoClass
    public static void main(String s[])
    Sub1 obj1=new Sub1(5);
    Sub1 obj2=new Sub1(6);
    thanks for reply

Maybe you are looking for

  • RAID 50

    I just installed 750GBx14 hard drives in Xserve RAID, and i was trying to configure them as RAID 50, my question is how to set up them as RAID 50?.. i dont know what ive done is right or not.. i need an advise. 1) i opened the Raid admin and i config

  • Issue linking external URL's in task list

    When I link a URL to a task list, a pop-up at the bottom of the screen saying "Only secure content is displayed" with a button saying "Show all content" When I select "Show all content" an Internet Explorer pop-up appears asking to either "Leave this

  • Testing simple JMS application

    I have written a very simple JMS application. I am trying to get it to run with the SUN App Server 8. I accepted the default values when installing the server. I have the app server up and running. The following code is suppose to create the Session:

  • Duplicate Podcasts and iTunes U Podcasts

    Does anyone know how I can search for and delete duplicate podcasts? the File>Display Duplicates option only seems to be available for Music files. Gerry

  • Error when trying to export to excel

    I have been having a problem with some of the dashboards I have been creating that export data to a csv file.  I used the process described here: http://biguru.wordpress.com/2008/04/26/export-data-out-of-your-xcelsius-dashboards/.  When I trigger the