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

Thread: Issue with abstract classes

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Issue with abstract classes

    Hi

    Maybe I'm missing something here but I can't seem to put abstract classes anywhere but in the same package as the class that extends it.

    For example, I create 2 classes like this:

    package abstracttest.testpackage2;
     
    public abstract class testAbstractClass {
           abstract void testMe();    
    }

    package abstracttest.testpackage1;
     
    import abstracttest.testpackage2.testAbstractClass;
     
    public class MainClass extends testAbstractClass {
        @Override
        void testMe() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }

    Looks perfectly valid to me, however, Netbeans reports this error "method does not override or implement a method from a supertype". Why?

    If I move the abstract class into the same folder as the mainClass it works! What's this all about?


  2. #2
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Issue with abstract classes

    Found out the answer why from another question in the forums


    The problem is the abstract method has to be declared public. All it was I was missing the public declaration....



  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Issue with abstract classes

    The problem is the abstract method has to be declared public. All it was I was missing the public declaration....
    Or protected. The code posted uses the default package private, which prevents access between packages. See Controlling Access

  4. #4
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Issue with abstract classes

    Please marked it solved , if solved
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

Similar Threads

  1. noob question on abstract classes
    By joshred in forum Object Oriented Programming
    Replies: 1
    Last Post: September 15th, 2010, 06:27 PM
  2. Java: interfaces and abstract classes
    By pinansonoyon in forum Object Oriented Programming
    Replies: 1
    Last Post: May 6th, 2010, 10:17 AM
  3. [SOLVED] Abstract Classes Help
    By SweetyStacey in forum Object Oriented Programming
    Replies: 10
    Last Post: May 6th, 2010, 06:15 AM
  4. A Question Regarding Abstract Classes & Packages
    By Kerubu in forum Object Oriented Programming
    Replies: 3
    Last Post: December 21st, 2009, 01:27 PM
  5. Java program with abstract class along with two subclasses
    By crazydeo in forum Collections and Generics
    Replies: 2
    Last Post: June 10th, 2008, 11:45 AM

Tags for this Thread