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 6 of 6

Thread: How come the AbstractBorder class is abstract?

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default How come the AbstractBorder class is abstract?

    It implements, I think, all the methods from the interface Border. Yet it's abstract. How is that possible? I thought that in java an abstract class had to have at least one abstract method. I was trying to make my own AbstractBorder subclass and was looking at the AbstractBorder class when I noticed this.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: How come the AbstractBorder class is abstract?

    Please test all of your assumptions by putting together an SSCCE.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: How come the AbstractBorder class is abstract?

    An SSCEE? I was asking pretty much how a class could be abstract without any abstract methods or unimplemented interface methods.

    Also, another thing, I can sub that class so far and only have some of its methods and yet I don't get that "It's abstract" bla bla bla error message.

    I checked and my subclass isn't abstract by default even if I had no methods in it.

    How can javax.swing.border.AbstractBorder be abstract and yet I have a subclass called MyBorder that has no methods in it and isn't abstract?

    It's a direct subclass in case you're wondering.

    I do see that the AbstractBorder class is a skeleton of sorts as it returns like default values and doesn't really do that much.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,267
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: How come the AbstractBorder class is abstract?

    I was asking pretty much how a class could be abstract without any abstract methods or unimplemented interface methods.
    ...
    How can javax.swing.border.AbstractBorder be abstract and yet I have a subclass called MyBorder that has no methods in it and isn't abstract?
    To quote the API for AbstractBorder:
    This provides a convenient base class from which other border classes can be easily derived.
    And to quote the Oracle description on Abstract classes
    An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
    A class is declared abstract because it lacks some type of implementation. In the case of AbstractBorder, it's does no painting and and has insets of size 0 - this default behavior is meant to be overriden/implemented

  5. The Following User Says Thank You to copeg For This Useful Post:

    javapenguin (June 21st, 2012)

  6. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: How come the AbstractBorder class is abstract?

    Quote Originally Posted by javapenguin View Post
    An SSCEE? I was asking pretty much how a class could be abstract without any abstract methods or unimplemented interface methods.
    Yes, an SSCCE. Had you simply tested your assumptions first by throwing together a little test program, you could have answered your own question.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: How come the AbstractBorder class is abstract?

    I did have such a test program. However, the results, which did point at what copeg was saying, conflicted with that I had long believed to be true about abstract, that is that I thought I needed at least one abstract method. Now I know otherwise.

Similar Threads

  1. Abstract class variable help
    By star12345645 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2012, 07:40 AM
  2. What's difference between public class and abstract class?
    By Java95 in forum Java Theory & Questions
    Replies: 7
    Last Post: January 24th, 2012, 06:37 AM
  3. Abstract class
    By jeskoston in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 26th, 2011, 01:46 PM
  4. abstract class
    By robinglow in forum Java Theory & Questions
    Replies: 2
    Last Post: August 20th, 2010, 01:36 AM
  5. abstract class
    By robinglow in forum AWT / Java Swing
    Replies: 2
    Last Post: August 20th, 2010, 01:36 AM