Results 1 to 6 of 6

Thread: Abstract class method overloading problem

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Abstract class method overloading problem

    Hello everyone,
    Well I guess my question is not complicated, but my knowledge of Java is very little and there fore I need some clarification. I have a file dep.java which contains the Class Relocation with some attributes private. Some methods Public and protected and a method public abstract seDeplcaer ();
    Code:
    Public abstract class dep / / I tried with and without abstract
    {
        private int posX;
        private int posY;
        private int Speed;
        private int View;
        private int rayonInfluence;
        Public abstract void Move();
     
       protected ...
    }
    Now I have another file dept.java where I define a dept class inheriting Relocation. In this class I defined the move method.
    Code:
    Public class dept extends dep
    {
     
        Public void Move(Animal [][] G)
        {
         ...
        }
     }
    But when i compile the program I get an error. Can any one help me with this, how to correct my code.
    Last edited by ISAIAH; 16-01-2010 at 10:13 AM.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Abstract class method overloading problem

    Hello,
    You are forced to write a method move () without arguments in your class Dept.java, because it is an abstract class the methods from the inherting class should be same as in the base class. In other ways you are not overload you are overriding methods.
    Code:
    public void Move () 
    {
    .
    .
    }
    Just make these changes and your code will compile properly.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: Abstract class method overloading problem

    Hello,
    You must define the function Move () in dept like this:
    Code:
    Public void Move() 
    {...
    }
    As dept is not abstract, it must define the abstract methods of travel.
    When you set off
    Code:
    Public void Move(Animal [][] G) 
    { ... 
    }
    you do not define the method public void Move () class movement, since the parameters are different.

  4. #4
    Join Date
    Dec 2009
    Posts
    202

    Re: Abstract class method overloading problem

    Hello,
    Ok, so this is the basic error in java, Truly speaking I did not knew that. Sorry for my mistake, but especially thank you very much for your help. Just one final point: is it normal that I must declare the class disp as abstract? If I want to use the method move with parameters. Thank you again for your help both of you.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Abstract class method overloading problem

    Hi,
    Yes, that is correct, if you want to use an abstract Standings you have use the same method as it is defined in the base or the super class, and the extended class should contain the same method as it is, without parameters in your case. If you would have not used the abstract key word then if you had use the move() method with parameters, it would be fine. That would work.

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Abstract class method overloading problem

    Hi,
    Just one final point: is it normal that I must declare the class disp as abstract?
    Yes and no, if you do not set the default to your method or methods by default (which are not abstract), you can ask yourself to spend some time on interface. Just for caution- your private attributes in your class travel are not visible to subclasses (eg dept). Hope this helps you. If you have any more problem do post back.

Similar Threads

  1. Method overloading c#.net
    By raju_srk in forum Software Development
    Replies: 1
    Last Post: 22-11-2010, 07:00 PM
  2. Static method in Abstract class
    By Anthony12 in forum Software Development
    Replies: 6
    Last Post: 12-08-2010, 10:22 AM
  3. Problem with abstract class and interface
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 08-03-2010, 12:20 PM
  4. Difference among concrete class and abstract class
    By Roxy_jacob in forum Software Development
    Replies: 4
    Last Post: 07-12-2009, 01:22 PM
  5. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 08:20 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,642,698.32271 seconds with 17 queries