何と呼ぶかはよくわかりませんが、基本的に、このコードを実行すると次のようになります。
public class test {
static Device one;
static Device two;
public static void main(String[] args) throws Exception {
one = new Device("One", "ONE");
System.out.println(one.getName());
two = new Device("Two", "TWO");
System.out.println(one.getName());
System.out.println(two.getName());
}
}
出力は次のとおりです。
ONE
TWO
TWO
いつあるべきか:
ONE
ONE
TWO
デバイスオブジェクトは非常に単純で、2つの文字列を受け取るだけで、2つ目は印刷するように要求している「名前」です。私は以前にOOPを行ったことがありますが、重要な側面を忘れているような気がしますが、それを理解できないようです。どんな助けでもありがたいです、ありがとう!
そして、これがデバイスコンストラクターです:
public Device(String iP, String Name) {
//Set the IP address
IP = iP;
//Set the device's name
name = Name;
// Set the string version of the device (for transmitting)
stringVersion = IP + ";" + name;
}