1 posts in topic
Flat View  Flat View

Posted By:   Shyma_j
Posted On:   Thursday, August 9, 2001 02:03 AM

What is wrong with this code?

interface inter


void checkmethod();


class test implements inter


void checkmethod(){}


when i tried to compile this code an error access modifier could not be made more restrictive was shown. why?

Re: Interface

Posted By:   Naveed_Azhar  
Posted On:   Thursday, August 9, 2001 03:47 AM

Dear Shyma,
As you know, unimplmented method in an interface are public ( in this example checkmethod() ). You can not use
private void checkmethod(); 
protected void checkmethod(); 

Now you have defined a class test which implements interfact "inter". There is a simple rule,
If you override a method accessiblity of overridden method should be equal or strong than than method in base-class or interface.

Accessiblity Level of Weaker to Strong are
1- Private 2- Friendly ( no accesiblity mentioned) 3- Protected 4-Public

So now, method in interface was Public ( Public is default accesiblity specifier for unimplemented methods in Interfaces )

But you have overridden it with Friendly ( default accessiblity specifier for classes ).

If you use

public void checkmethod(){}

in test class there should be no error message.

About | Sitemap | Contact