What does this ArrayList code print?
import java.util.*;
List<Integer> xs = new ArrayList<>();
xs.add(1);
xs.add(2);
System.out.println(xs.get(0) + xs.get(1));
❓ الوراثة مع مُنشئ أب مُعَلَّم
Inheritance with parameterized base constructor
Inheritance with parameterized base constructor
class Base { Base(int x) {} }
class Child extends Base { }
جافا Java
❓ الوراثة مع مُنشئ أب مُعَلَّم Inheritance with parameterized base constructorclass Base { Base(int x) {} } class Child extends Base { }
Choose your answer:
Anonymous Quiz
40%
Compiles successfully
36%
Does not compile: Child must call super(int)
25%
Does not compile: Base needs a no-arg constructor
👍3
❓ التعامل مع الاستثناءات في finally
Try-catch-finally order
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");
}❓ الاستثناءات المُتَحَقَّقة (Checked)
Checked exceptions handling
Checked exceptions handling
void read() throws java.io.IOException {}
void m(){ read(); }
جافا Java
❓ الاستثناءات المُتَحَقَّقة (Checked) Checked exceptions handlingvoid read() throws java.io.IOException {} void m(){ read(); }
Choose your answer:
Anonymous Quiz
36%
Compiles: unchecked exceptions only
50%
Does not compile: must handle or declare the checked exception
14%
Runtime error only
❓ تفضيل التحويلات في Overload
Overload preference (widening vs boxing vs varargs)
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);❓ ترتيب التهيئة: static ثم instance ثم constructor
Initialization order
Initialization order
class X {
static { System.out.print("S"); }
{ System.out.print("I"); }
X(){ System.out.print("C"); }
}
new X();❓ إخفاء الحقول (Field Hiding)
Field hiding resolution
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);