tag:blogger.com,1999:blog-4650874658008990222.post6063885211006840873..comments2023-09-29T03:01:11.998-07:00Comments on Java 'n More: Why this code does not compile successfully?K.A.N.Nancyhttp://www.blogger.com/profile/04428346391568619474noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-4650874658008990222.post-88242899085207336052014-01-20T03:21:30.364-08:002014-01-20T03:21:30.364-08:00Awesome. Methods declared in an interface by defau...Awesome. Methods declared in an interface by default are public and abstract. And when a class implements an interface it can broden the scope but cannot narrow it. Default access in class for any method or attribute is package level access. Hence in class public method cannot be overridden as package level. A method from interface MUST be always public in class... :) enjoy Java :)K.A.N.Nancyhttps://www.blogger.com/profile/04428346391568619474noreply@blogger.comtag:blogger.com,1999:blog-4650874658008990222.post-30313330933723367232014-01-20T02:48:18.944-08:002014-01-20T02:48:18.944-08:00It is good practice to have an access specifiers a...It is good practice to have an access specifiers and qualifiers to the interface method declarations. Anonymoushttps://www.blogger.com/profile/08960395572365733178noreply@blogger.comtag:blogger.com,1999:blog-4650874658008990222.post-14302666788362693522014-01-19T11:42:05.950-08:002014-01-19T11:42:05.950-08:00Hi, Interface methods are Public abstract by defau...Hi, Interface methods are Public abstract by default.<br /><br />Like:- Your interface<br /><br />public interface JustAnInterface {<br /> public abstract void testIt();<br />}<br /><br />But in your class your method is having default access modifier which is having less visibility than public method declaried in interface so your class throws compile time error . Your class should be like.<br /><br />//JustAClass.java<br />public class JustAClass implements JustAnInterface{<br /> void testIt(String msg){<br /> System.out.println(msg);<br /> }<br /><br /> public void testIt(){<br /> System.out.println("I am from an Interface");<br /> }<br />}<br />SOURABH AGGARWALhttps://www.blogger.com/profile/03809025848221508784noreply@blogger.comtag:blogger.com,1999:blog-4650874658008990222.post-33146214952415063542014-01-19T04:38:36.930-08:002014-01-19T04:38:36.930-08:00The interface method testIt() is implicitly public...The interface method testIt() is implicitly public, but the implementation in JustAClass is package-private, and the compiler doesn't allow a subtype to reduce the visibility of a virtual method.archttps://www.blogger.com/profile/13388121023546475814noreply@blogger.comtag:blogger.com,1999:blog-4650874658008990222.post-52675611941780452702014-01-19T03:36:11.821-08:002014-01-19T03:36:11.821-08:00 visibility of the inherited method from JustAnint... visibility of the inherited method from JustAninterface.JustAnInterface in not accessiable <br />for method void testIt()Anonymoushttps://www.blogger.com/profile/01574751519863864634noreply@blogger.com