Results 1 to 8 of 8
Thread: Over-riding purpose fails..
- 08-22-2008, 10:28 PM #1
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..
- 08-23-2008, 03:52 AM #2
Have you tried to compile this code?
My compiler complains for exactly the reason you suggest.
- 08-23-2008, 05:23 AM #3
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();
}
}
- 08-23-2008, 05:47 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 08-23-2008, 06:02 AM #5
Eranga , please refer to the post in the start of this thread.
- 08-23-2008, 11:55 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 08-24-2008, 12:32 AM #7
- 08-24-2008, 04:14 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ya, that's true. Anyway, I'll try to explain it as much clear.
Similar Threads
-
cannot open database requested in login. Login fails
By banduskank in forum JDBCReplies: 0Last Post: 06-25-2008, 12:41 PM -
Setting cookie fails when jarred
By damounh in forum Java AppletsReplies: 0Last Post: 05-08-2008, 02:41 PM -
interface purpose?
By frejon26 in forum New To JavaReplies: 4Last Post: 01-24-2008, 03:39 AM -
Repaint fails when using threads
By rjevans2000 in forum Threads and SynchronizationReplies: 1Last Post: 09-21-2007, 11:22 PM -
Repaint fails when using threads
By rjevans2000 in forum AWT / SwingReplies: 3Last Post: 08-15-2007, 05:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks