Inheriting from an abstract class

Hi all,
I'm using a certain graphics package and I need to modify a functionality of one of its classes called, say, PlainAxis. For this purpose I define a class MyAxis that derives from the class Axis which is the base class for PlainAxis as well. The Axis class is abstract; it has two abstract methods - draw() and copy(). I provide these two methods in MyAxis, so, it can be instantiated. Still I get the following error message during the compilation:
MyAxis should be declared abstract; it does not define draw() in Axis
Here is the command I'm executing (sgt.jar contains classes of the graphics package I'm using):
javac -g -classpath .:./sgt.jar *.java -d .
What am I doing wrong? Why does this error occure for the draw() method only?
Thank you for the help!

You probably didn't define draw() with the exactsame
method signatureBelieve me I did :) This was the first thing I
checked when I saw this error for the first time...
Any other suggestions? :)The possibilities that I can think of are (most of these have already been suggested):
1. you didn't define draw with the correct signature
2. you're not extending the class you think you're extending
3. you're not compiling the class you think you're compiling
4. there's a bug in your compiler
I'd say 3 is extremely unlikely. So without seeing your code, we can only guess, but I would guess #1.

Similar Messages

  • WebService from an Abstract Class

    Winthin JDev 10.1.2 is there a way to automatically create a J2EE WebService from an abstract class as you would with an public class? If so, how? Thank you in advance.

    Justin,
    may I ask what you hope to achieve by exposing an abstract class as a Webservice?
    Frank

  • ER: Java class diagrams do show inheritance from no-sourcecode classes

    Hi!
    We just noticed that when we extend some classes for which the source code is not available, such inheritance is not visible on diagrams.
    I would like to propose ER to show these inheritances (as the no-source classes signatures are enough to display the class on diagram). It is very inconvenient to have diagrams without possibility to depict the inheritance from many Oracle classes, as this inheritance is more and more important for building ADF applications.
    Thanks for consideration.
    PaKo

    Pako,
    I filed the ER
    Frank

  • Calling a method from an abstract class in a seperate class

    I am trying to call the getID() method from the Chat class in the getIDs() method in the Outputter class. I would usually instantiate with a normal class but I know you cant instantiate the method when using abstract classes. I've been going over and over my theory and have just become more confused??
    Package Chatroom
    public abstract class Chat
       private String id;
       public String getID()
          return id;
       protected void setId(String s)
          id = s;
       public abstract void sendMessageToUser(String msg);
    Package Chatroom
    public class Outputter
    public String[] getIDs()
         // This is where I get confused. I know you can't instantiate the object like:
            Chat users=new Chat();
            users.getID();
    I have the two classes in the package and you need to that to be able to use a class' methods in another class.
    Please help me :(                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I have just looked over my program and realised my class names are not the most discriptive, so I have renamed them to give you a clearer picture.
    package Chatroom
    public abstract class Chatter
    private String id;
    public String getID()
    return id;
    protected void setId(String s)
    id = s;
    I am trying to slowly build a chatroom on my own. The Chatter class is a class that will be used to represent a single logged in user and the user is given an ID when he logs in through the setId and getID() methods.
    package Chatroom;
    import java.util.Vector;
    public class Broadcaster
    private Vector<Chatter> chatters = new Vector<Chatter>();
    public String[] getIDs()
    // code here
    The Broadcaster class will keep a list of all logged-in users keeps a list of all the chats representing logged-in users, which it stores in a Vector.I am trying to use the getIDs() method to return an array of Strings comprising the IDs of all logged-in users, which is why im trying to use the getID() method from the Chat class.
    I apologise if I come across as clueless, it's just I have been going through books for about 4 hours now and I have just totally lossed all my bearings

  • Inheritance  from interface ans class

    Hi All
    Say I have interface A and class B.
    Now I creating class C extands B implements A
    who is C's super class? the class or the interface?
    Can I write somthing like this?
    A name = new C() or B name = new C()?
    Thank u in advance
    Eyal

    Hi All
    Say I have interface A and class B.
    Now I creating class C extands B implements A
    who is C's super class? the class or the interface?The class, because you said superclass.
    Can I write somthing like this?
    A name = new C() or B name = new C()?
    Thank u in advance
    EyalDo you have access to a compiler? You could try it and see faster than you
    would get an answer from the forum.

  • Abstract Class that implements Comparable

    I am trying to understand how a comparable interface works with an abstract class. Any help is greatly appreciated.
    I have a class ClassA defined as follows:
    public abstract class ClassA implements Comparable I have a method, compareTo(..), within ClassA as follows:
    public int compareTo(Object o) I have a sub-class ClassB defined as follows:
    public class ClassB extends ClassAI am receiving a compile error:
    Class must implement the inherited abstract method packagename.ClassA.compareTo(Object)
    Should or can the compareTo be abstract in ClassA and executed in ClassB? Just not sure how this works.

    ???? if you are inheriting from an abstract class your subclass must implement methods that were declared in the parent (abstract) class but not implemented
    When in doubt, refer to the Java Language Specification..

  • Why are we using Abstract class?

    Why are we using Abstract class? What is specify use of Abstract class?

    The way I understand it....and I may be wrong because
    I am very new....is that by making the class abstract
    you will add abstract methods to it. Those abstract
    methods MUST be defined in in any subclass that
    inherits from the abstract class thereby making the
    abstract a template for subclasses.
    If your animal class is abstract then you would need
    an abstract method (Which is just siganture, no body)
    of say "numberOfLegs". Then in your dog and cat
    classes which extend animal you must define a
    "numberOfLegs" method with appropriate code.it isn't mandatory for an abstract class to have abstract methods. if a class does have abstract methods, the class must be abstract. but the following is perfectly legal
    public abstract class NoAbstractMethods {
      public void doStuff() {
         // do stuff
    }a subclass of an abstract class can also be abstract, and as such need not implement any additional methods

  • VS2013.4 Class Diagram inheriting from a base type (how do I)

    Hi Folks,
    I am creating a VS2013.4 class diagram and one of my classes inherits from a base class System.Configuration.ProviderBase.
    In VS2010 there is a way to do this and the class new class would show (Abstract Class -> ProviderBase) in its description.   Is there a way to
    When I look at the properties for the class there is no property specifying inheritance.  In VS2010 there is an 'Inherits' property.
    Regards
    Andy

    If the User-Agent contains "Fennec/" then it is Firefox for mobile. If it contains "Android" then it is running on an Android device.
    We have an open request to add more device info to the User-Agent header. For details, see:
    https://bugzilla.mozilla.org/show_bug.cgi?id=625238
    We'll consider this request, but we must balance it against user privacy, and attacks like browser fingerprinting. For now, in cases where you don't detect a known device from the User-Agent header, you can ask the user instead (for example, have them choose from a list of devices). This will also benefit Android users who have changed their browsers' User-Agent headers for various reasons.

  • From abstract class to public class

    I am developing a editor base application...wondering that how to cancel the abstract class and put all the abstract class methods into the public class..?? thanks

    Is this a C++ question? If so, you should post it in the C++ forum. If it is a Java question, post in the Java forum.
    In either case, please make your question more specific. It sounds like all you have to do is copy the functions from the abstract class to the derived class, remove the dependency on the abstract class, and delete the abstract class from the source code. Presumably that is not what you are asking.

  • Abstract class implements Cloneable... How?

    I have an abstract class that is inherited by many many subclasses. I wish to make this abstract class a cloneable.
    Most of the subclasses are using the protected fields inherited from the abstract one, they almost never add any extra field. So it would make a lot of sense to implement the clone() method at the abstract level. And not doing so would cost me a lot of time.
    But that causes me trouble, because you can't write something like this :
    public abstract class MyAbstractClass implements Cloneable {
        protected Source source; // the two fields the subclasses are satisfied with, most the time
        protected Vectro<Target> targets;
        public Effect clone() {
            return new Effect(source , targets);  // when a subclass has extra fields, I plan to overwrite clone()
    }Because you can't instantiate an abstract class, of course. Anyway, I'd rather instatiate a class of the appropriate concrete class.
    I feel there is a way to hack this. I feel there is a way to avoid having to write the same clone() method in every subclass.
    Anyone?
    Thanks.

    jverd wrote:
    bestam wrote:
    Most of the subclasses are using the protected fields inherited from the abstract one, Bad idea. Make the fields private and provide protected get/set methods.Is this a general recommendation or only in the context described by the OP?
    Because API classes don't do this in many cases. Just looked at a random one: AbstractButton.

  • A Singleton variable in an Abstract Class

    Hello there people
    I have a quick question. I have made an abstract class in which I want to put an identifier (ID) int to be incremented whenever I make any of the concrete class instances that extend this abstract class.
    whould that declairation be as follows?:
    public static int IDAdditionally, I have a quick question about abstract constructors. If constructors are defined in the concrete classes, are their declairations needed in the abstract class?
    and finally, if I wanted to use the int ID (as mentioned above) then would I have to use constructor from the abstract class?
    thanks in advance for the help

    I think the OP would want a constructor in the abstract class to update that variable. Otherwise, he'd have to remember to update it in the constructor for all concrete classes. But, you don't declare constructors for the concrete class in the abstract class. You only declare constructors for the abstract class in the abstract class.

  • Abstract class - access to parent

    Hi:
    I would like to do the following, but I don´t know how (neither if its possible):
    Access from an abstract class a method of its implementer class.
    public class ContainerClass () implements AbstractClass{
    public void AbstractMethod(){
    super().Method1();
    public abstract class AbstractClass(){
    public void Method1(){
    parent.AbstractMethod();
    parent.getClassName(); // I am expecting ContainerClass
    public void AbstractMethod();
    The method Method1 will be the same for every class implementing AbstractClass, but dependent of the implementation of the AbstractMethod in the container class.
    Theoretically, the ContainerClass object should have all the methods implemented in runtime, therefore, all of them accessible in the same object.
    Does anybody know how to do this?
    Cheers!

    You'll probably want to look a bit into the differences between an interface and an abstract class. Here, you're defining AbstractClass which provides a 'default' set of behaviors for another object that will extend it, but you are trying to use it as an interface, which defines what methods must be available.
    For example, if you were defining a few shapes and wanted common behavior to be available, you might define it as an interface:
    public interface Shape {
      public int area();
    public class Square implements Shape {
      private int length;
      public Square(int length) {
        this.length = length;
      public int area() {
        return length * length;
    }By defining Shape as an interface, you guarantee that every class implementing it will have 'public int area()'.
    An abstract class is a little different. It would let you do things like this:
    public abstract class AbstractShape {
      public abstract int area();
      public String toString() {
        return "The area of this shape is " + area();
    public class Square extends AbstractShape {
      // Same code as before
    }It would define default code (which you can also override) as well as certain methods which you must override (or be abstract). These two approaches could also be combined, making AbstractShape and/or Square also implement Shape, which is what a lot of Java API classes do. For example, the List interface defines methods that must be available (like add(), remove(), etc). It also has AbstractList, which implements many of the required List methods, but not all. A class that extends AbstractList only needs to implement a few more methods to be fully usable.

  • Downcasting Abstract Class.

    problem goes like this. I have and abstract class A[which extends Thread ] and three another classes B,C,D extending from this Abstract class A.
    In the main class at runtime,I will be getting the class name[B or C or D] to be instantiated. Also newInstance() of Class cannot be called as the Constructors for the classes B ,C ,D are different from the default.
    Can anyone suggest a wayout.

    In the main class at runtime,I will be getting the
    class name[B or C or D] to be instantiated. Also
    newInstance() of Class cannot be called as the
    Constructors for the classes B ,C ,D are different
    from the default.
    Can anyone suggest a wayout.Erm, you haven't actually asked a question - what is the problem?
    Assuming that you want to instantiate a class whose name you don't know until runtime (though I don't see what this has to do with the title of the topic), then you can use Class.getDeclaredConstructor or Class.getDeclaredConstructors and then Constructor.newInstance

  • Abstract class vs Interface difference

    hi guys
    As such i know the basic difference ,but i want toknow what is the differnece between a interface and an abstract class with all the abstract methods in it.
    thanks a lot
    yash

    ,but i want
    want to know what is the differnece between a
    interface and an abstract class with all the abstract
    methods in it.You can view a class and an interface as being on the opposite extreme ends on a concrete-abstract scale.
    Say you start out with a fully concrete class. Just by adding the abstract keyword the class becomes abstract. You then remove implementation from this abstract class by making more and more methods abstract and finally you also make all methods public. You now basically have an interface. You just replace abstract class with interface and there you are.
    Basically Java wouldn't have to define an interface. The compiler could recognize and mark totally abstract classes as "interfaces" internally. The rules for extension would be that you can only extend one class carrying implementation. All other classes must be totally abstract. But admittedly, the system with declared interfaces is much more convenient for the programmer. You know up front just by looking at it that this "class" must stay totally abstract.

  • Abstract class sub-classing

    Hi there...
    I want to know whether the following is true:
    "you cannot declare an object of a class, derived from an abstract class, to be null initially and then later instantiate it. you have to instantiate it right away in one statement"

    REnviron = sub-class of an abstract class...
    i want only one unique instance of REnviron to exist in the application.. thats why, i do:
    private static REnviron uniqueInstance = null;
    /* Creates a new instance of REnviron */
    private REnviron() { }
    public static REnviron getREnvironInstance(){
    if(uniqueInstance==null) uniqueInstance = new REnviron();
    return uniqueInstance;
    this method (getREnvironInstance()) will only be called once in some other class.
    However, when i run, the error mentioned previously is "thrown on my face"

Maybe you are looking for