クラスがJavaで持つことができる変数のタイプは何ですか?
クラスがJavaで持つことができる変数には、ローカル変数、インスタンス変数の3つの異なるタイプがあります。 、およびクラス/静的 変数。
例
public class LocalVariableTest {
public void show() {
int num = 100; // local variable
System.out.println("The number is : " + num);
}
public static void main(String args[]) {
LocalVariableTest test = new LocalVariableTest();
test.show();
}
} The number is : 100
public class InstanceVariableTest {
int num; // instance variable
InstanceVariableTest(int n) {
num = n;
}
public void show() {
System.out.println("The number is: " + num);
}
public static void main(String args[]) {
InstanceVariableTest test = new InstanceVariableTest(75);
test.show();
}
} The number is : 75
public class StaticVaribleTest {
int num;
static int count; // static variable
StaticVaribleTest(int n) {
num = n;
count ++;
}
public void show() {
System.out.println("The number is: " + num);
}
public static void main(String args[]) {
StaticVaribleTest test1 = new StaticVaribleTest(75);
test1.show();
StaticVaribleTest test2 = new StaticVaribleTest(90);
test2.show();
System.out.println("The total objects of a class created are: " + count);
}
} 出力
The number is: 75 The number is: 90 The total objects of a class created are: 2
-
Java 9での@Deprecatedアノテーションの改善点は何ですか?
@Deprecatedで注釈を付けることができる要素 この特定の要素が以下の理由で使用されなくなったことを意味します 使用するのは危険であり、エラーが発生する可能性があります。 将来のバージョンでは互換性がなくなる可能性があります。 将来のバージョンで削除される可能性があります。 より優れた、より効率的なソリューションがそれに取って代わりました。 Java 9には、次の2つの新しい要素が追加されています。以降 およびforRemoval 属性。 1)以降: この要素は、注釈付きAPI要素の非推奨バージョンを指定します。 2)forRemoval: 注釈付きのAPI要素を表す
-
JavaでのCursorクラスの重要性は何ですか?
カーソル オブジェクトのサブクラスです クラスであり、ポイントまたはインジケーターとして定義できます。 画面上。 カーソル ユーザーがマウスで操作するシステムからの入力を選択するために使用されます 。 カーソルで使用できるさまざまな種類のカーソル クラスはDEFAULT_CURSOR、CROSSHAIR_CURSOR、HAND_CURSOR、TEXT_CURSOR、WAIT_CURSOR Cursorクラスの重要なメソッドは、 getDefaultCursor()、getName()、getPredefinedCursor()、getSystemCustomCursor()です。 およびge