Results 1 to 2 of 2

Thread: private

  1. #1
    Gary_10 is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default private

    Hi all, I' m new in forum, i have a problem i need your help:

    //File Fin.java
    class Base{
    private void amethod(){
    System.out.println("amethod");
    }
    }
    public class Fin extends Base{
    public final void amethod(){
    System.out.println("Fin: amethod");
    }
    public static void main(String argv[]){
    Base b = new Base();
    b.amethod();
    }
    }

    The error is: amethod() has private access in Base. I know if i delete private it could access, but i must keep private and find a different way to run this program without errors... Any ideas ?:confused:

    P.S: Sorry for my English.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    class Base{
        private void amethod(){
            System.out.println("amethod");
        }
        public void accessAmethod() {
            amethod();
        }
    }
    public class Fin extends Base{
        public final void amethod(){
            System.out.println("Fin: amethod");
        }
        public static void main(String argv[]){
            Base b = new Base();
            b.accessAmethod();
            new Fin().amethod();
        }
    }

Similar Threads

  1. private array
    By tnght in forum New To Java
    Replies: 10
    Last Post: 12-05-2009, 09:43 AM
  2. More than one input in one private method
    By rice in forum New To Java
    Replies: 0
    Last Post: 10-02-2009, 06:08 AM
  3. Private constructor and super()
    By Basit56 in forum Advanced Java
    Replies: 9
    Last Post: 08-21-2009, 07:19 AM
  4. Private Classes Clarification
    By justlearning in forum New To Java
    Replies: 1
    Last Post: 05-06-2008, 11:51 PM
  5. Question of private member
    By Felissa in forum Advanced Java
    Replies: 2
    Last Post: 06-28-2007, 10:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •