Java: reusable encapsulation with interface, abstract class or inner classes?
- by HH
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!
Exception 'illegal type' from interface apparently because values being constants(?!)
static interface userInfo
{
File startingFile=new File(".");
String startingPath="dummy";
try{
startingPath=startingFile.getCanonicalPath();
}catch(Exception e){e.printStackTrace();}
}
Working code but no succes with non-static inner class
import java.io.*;
import java.util.*;
public class listTest{
public interface hello{String word="hello word from Interface!";}
public static class hej{
hej(){}
private String hejo="hello hallo from Static class with image";
public void printHallooo(){System.out.println(hejo);}
}
public class nonStatic{
nonStatic(){}
//HOW TO USE IT?
public void printNonStatic(){System.out.println("Inside static class with an image!");}
}
public static void main(String[] args){
//INTERFACE TEST
System.out.println(hello.word);
//INNNER CLASS STATIC TEST
hej h=new hej();
h.printHallooo();
//INNER CLASS NON-STATIC TEST
nonStatic ns=new nonStatic();
ns.printNonStatic();
//IS there a way to it without STATIC?
}
}
Output
The above code works but how non-staticly? Output:
hello word from Interface!
hello hallo from Static class with image!
StaticPrint without an image of the class!
Related
Nesting classes
inner classes?
interfacses