私はカプセル化しようとします。インターフェイスからの例外、静的な内部クラスの動作、非静的な内部クラスの動作しない、用語を理解できない: 入れ子になったクラス、内部クラス、入れ子になったインターフェイス、インターフェイス抽象クラス -- 繰り返しのように聞こえる!
悪い!--- 明らかに値が定数であるため、インターフェイスからの例外「不正な型」(?!)
static interface userInfo
{
File startingFile=new File(".");
String startingPath="dummy";
try{
startingPath=startingFile.getCanonicalPath();
}catch(Exception e){e.printStackTrace();}
}
それを行う多くの方法: インターフェイス、静的な内部クラスのイメージ VS 非静的な内部クラスのイメージ
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);
}
}
出力
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!
関連している
- 入れ子クラス
- 内部クラス?
- インターフェース