Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Abstract method in a non-abstract class

  1. #1
    Junior Member bassie's Avatar
    Join Date
    Nov 2012
    Posts
    24
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Abstract method in a non-abstract class

    Is there any way of achieving this, or some way of achieving the same result in another way?

    I basically have an abstract method in a class, which is of course also abstract. I have another class, however, in which I want to instantiate a copy of the previously mentioned abstract class, but I'm not allowed to do this due to the fact that the latter class is not abstract.

    Any ways around this?

    Does simply changing the class to an abstract one actually affect any implementation or is it just used as a means of implementing abstract methods?

    Thanks for your time


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Abstract method in a non-abstract class

    You cannot have any unimplemented methods in a non-abstract class.

    You cannot instantiate an instance of any abstract class, even if the abstract class has no abstract methods.

    A common work-around is to provide a "dummy" implementation of all abstract methods you don't want to support, though the validity of this method varies from case to case.

    The dummy implementation can either do nothing or throw an exception, say an UnsupportedOperationException.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    bassie (December 2nd, 2012)

  4. #3
    Junior Member bassie's Avatar
    Join Date
    Nov 2012
    Posts
    24
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Abstract method in a non-abstract class

    thanks helloworld, I just created an empty method and got rid of all the abstracts and now that problem appears to be solved

Similar Threads

  1. GUI error: is not abstract and does not override abstract method
    By djl1990 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 21st, 2011, 02:26 PM
  2. Abstract class
    By jeskoston in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 26th, 2011, 02:46 PM
  3. Replies: 2
    Last Post: February 28th, 2011, 10:51 AM
  4. abstract class
    By robinglow in forum Java Theory & Questions
    Replies: 2
    Last Post: August 20th, 2010, 02:36 AM
  5. abstract class
    By robinglow in forum AWT / Java Swing
    Replies: 2
    Last Post: August 20th, 2010, 02:36 AM