Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: reusable encapsulation with interface, abstract class or inner classes?
    primarykey
    data
    text
    <p>I try to encapsulate. Exeption from interface, static inner class working, non-static inner class not working, cannot understand terminology: nested classes, inner classes, nested interfaces, interface-abstract-class -- sounds too Repetitive!</p> <p><strong>BAD! --- Exception 'illegal type' from interface apparently because values being constants(?!)</strong></p> <pre><code> static interface userInfo { File startingFile=new File("."); String startingPath="dummy"; try{ startingPath=startingFile.getCanonicalPath(); }catch(Exception e){e.printStackTrace();} } </code></pre> <p><strong>MANY WAYS TO DO IT: Interface, static inner class image VS non-static innner class image</strong></p> <pre><code>import java.io.*; import java.util.*; public class listTest{ public interface hello{String word="hello word from Interface!";} public static class staticTest{ staticTest(){} private String hejo="hello hallo from Static class with image"; public void printHallooo(){System.out.println(hejo);} } public class nonStatic{ nonStatic(){} public void printNonStatic(){System.out.println("Inside non-static class with an image!");} } public static class staticMethodtest{ private static String test="if you see mee, you printed static-class-static-field!"; } public static void main(String[] args){ //INTERFACE TEST System.out.println(hello.word); //INNNER CLASS STATIC TEST staticTest h=new staticTest(); h.printHallooo(); //INNER CLASS NON-STATIC TEST nonStatic ns=(new listTest()).new nonStatic(); ns.printNonStatic(); //INNER CLASS STATIC-CLASS STATIC FIELD TEST System.out.println(staticMethodtest.test); } } </code></pre> <p><strong>OUTPUT</strong></p> <pre><code>hello word from Interface! hello hallo from Static class with image Inside non-static class with an image! if you see mee, you printed static-class-static-field! </code></pre> <p><strong>Related</strong></p> <ul> <li><a href="http://mindprod.com/jgloss/nestedclasses.html" rel="nofollow noreferrer">Nesting classes</a></li> <li>inner classes?</li> <li>interfacses</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload