Results 1 to 8 of 8
  1. #1
    udayadas's Avatar
    udayadas is offline Member
    Join Date
    Aug 2008
    Posts
    22
    Rep Power
    0

    Default Over-riding purpose fails..

    I care a class like

    abstract class Animal
    {
    protected abstract void getSound();
    }

    Being author of the class I wan the method to have a restricted access(I dont want it to be publicly accessible)

    My friend goes one step ahead of me...

    class Dog extends Animal
    {
    public void getSound()
    {
    ---
    ---
    }

    }


    Dont you think it is a flaw in java if the overriding class broadens the access level of an overridden method, because it was decided to make protected with some intention back in mind..

  2. #2
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    Have you tried to compile this code?

    My compiler complains for exactly the reason you suggest.

  3. #3
    udayadas's Avatar
    udayadas is offline Member
    Join Date
    Aug 2008
    Posts
    22
    Rep Power
    0

    Default

    I'm surprised

    My compiler does not trap it..I have been using Java 6 and also netbeans 6.1.It goes smooth with both of them.

    I am a bit confused...lets wait other to respond to this....Belo I am submitting the code that i am using "Dog.java";

    abstract class Animal
    {
    protected abstract void getSound();
    }
    //----------------
    public class Dog extends Animal
    {
    public void getSound()
    {
    System.out.println("SOund");
    }
    public static void main(String []s){
    Dog d=new Dog();
    d.getSound();

    }
    }

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I've tried this on NetBeans 6.1 and Java 6.

    Basically it's complain about the non-public access on the public Dog class. But it's fine. So what you are looking here. There is any issues related to access level.

  5. #5
    udayadas's Avatar
    udayadas is offline Member
    Join Date
    Aug 2008
    Posts
    22
    Rep Power
    0

    Default

    Eranga , please refer to the post in the start of this thread.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Yes I do pal. I've an idea what you are trying to say. That's why I'm confusing.

    If you use default or private access level, compiler complain about the weaker access privileges of the Dog class. Basically you have to use either public or protected access privileges. Basically that's the most secure access level can be use.

  7. #7
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    Quote Originally Posted by Eranga View Post
    That's why I'm confusing.
    Language nit, I assume that you meant "that's why I'm confused".

    If you are "confusing" then you are trying to confuse others, like George Bush does a lot when he talks.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Replies: 0
    Last Post: 06-25-2008, 12:41 PM
  2. Setting cookie fails when jarred
    By damounh in forum Java Applets
    Replies: 0
    Last Post: 05-08-2008, 02:41 PM
  3. interface purpose?
    By frejon26 in forum New To Java
    Replies: 4
    Last Post: 01-24-2008, 03:39 AM
  4. Repaint fails when using threads
    By rjevans2000 in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-21-2007, 11:22 PM
  5. Repaint fails when using threads
    By rjevans2000 in forum AWT / Swing
    Replies: 3
    Last Post: 08-15-2007, 05:42 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
  •