جافا Java
前往频道在 Telegram
6 175
订阅者
-324 小时
-207 天
-7130 天
帖子存档
6 171
❓ استخدام this للإشارة لحقل مُغَطّى
Using this to refer to a shadowed field
class T {
int n = 10;
void set(int n){ n = n; }
int get(){ return n; }
}
T t = new T();
t.set(5);
System.out.println(t.get());6 171
❓ إخفاء الحقول (Field Hiding)
Field hiding resolution
class A { int v = 1; }
class B extends A { int v = 2; }
B b = new B();
System.out.println(((A)b).v);6 171
❓ ترتيب التهيئة: static ثم instance ثم constructor
Initialization order
class X {
static { System.out.print("S"); }
{ System.out.print("I"); }
X(){ System.out.print("C"); }
}
new X();6 171
❓ تفضيل التحويلات في Overload
Overload preference (widening vs boxing vs varargs)
static void m(long x){ System.out.print("long"); }
static void m(Integer x){ System.out.print("Integer"); }
static void m(int... x){ System.out.print("varargs"); }
m(5);6 171
❓ الاستثناءات المُتَحَقَّقة (Checked)
Checked exceptions handling
void read() throws java.io.IOException {}
void m(){ read(); }6 171
❓ التعامل مع الاستثناءات في finally
Try-catch-finally order
try {
int x = 1 / 0;
System.out.print("A");
} catch (ArithmeticException e) {
System.out.print("B");
} finally {
System.out.print("C");
}6 171
❓ الوراثة مع مُنشئ أب مُعَلَّم
Inheritance with parameterized base constructor
class Base { Base(int x) {} }
class Child extends Base { }