Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

why java is giving 'attempting to assign weaker access privileges' error?

843785Aug 29 2008 — edited Aug 29 2008
Can some one can tell me why java is giving 'attempting to assign weaker access privileges' compile error while compiling Abhishekchild.java ?
The two classes is :
public class  Abhishek {
	

	  void asd() 
	{
	System.out.println("hello");
	}
		static String a;
		public static void main (String st[])
		{

}
}


public class  Abhishekchild extends Abhishek {
	

	private  void asd() 
	{
	System.out.println("hello");
	}
		static String a;
		public static void main (String st[])
		{
			
}
}
In my opinion, java compiler is showing the error , as method asd has public visibility in Abhishek. java so
(i)it should be visble to all sub classes of Abhishek.java.
But if we override this function in Abhishekchild.java, and change the visibility to private then it will not be available for child of Abhishekchild.java. But these children are also children of Abhishek.java*, but this violates rule (i).*
So java shows a compilation error.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 26 2008
Added on Aug 29 2008
5 comments
6,174 views