اختبار شامل لكل مواضيع المقرر: من الدوال حتى قواعد البيانات.
الاختبار النهائي الشامل
يغطّي المقرر كاملًا. إجاباتك تُحفظ تلقائيًّا على هذا الجهاز؛ أجب ثم اضغط «صحّح ورقتي».
1السؤال الأول: اختر الإجابة الصحيحة
1) الدالة التي لا تعيد قيمة نوعها:
2) ما الناتج؟
snippet×
SourceHistory⟲⟳🔍
publicclass Main{staticint pw(int b, int e) {if (e == 0) return1;return b * pw(b, e - 1); }publicstaticvoid main(String[] args) {System.out.println(pw(2, 3)); }}
3) الكائن هو:
4) اسم دالة البناء:
5) لاستيراد كل كلاسات java.util:
6) المحدد الذي يقصر الوصول على الكلاس:
7) المتغير المشترك بين كل الكائنات:
8) في التغليف، الشرط يوضع في:
9) ما الناتج؟
snippet×
SourceHistory⟲⟳🔍
class P{ P() { System.out.print("P"); }}class C extends P{ C() { System.out.print("C"); }}publicclass Main{publicstaticvoid main(String[] args) {new C(); }}
10) ما الناتج؟
snippet×
SourceHistory⟲⟳🔍
class Animal{String name() { return"Animal"; }}class Cat extends Animal{ @OverrideString name() { return"Cat"; }}publicclass Main{publicstaticvoid main(String[] args) { Animal a = new Cat();System.out.println(a.name()); }}
11) الكلاس الذي لا يُنشأ منه كائن:
12) finally:
13) الكلاس المستخدم للكتابة إلى ملف:
14) المكوّن الذي يمثّل زرًّا في Swing:
15) أمر SQL لقراءة البيانات:
16) الكلاس ينفّذ الواجهة باستخدام الكلمة:
17) لمعرفة عدد عناصر القائمة ArrayList نستخدم:
2السؤال الثاني: صح أم خطأ
1) Overloading يكون بين الأب والابن.
الصواب: خطأ
2) protected يتيح الوصول للكلاسات الوارثة في حزمة أخرى.
الصواب: صح
3) لا تدعم جافا وراثة كلاس من كلاسين بـ extends.
الصواب: صح
4) SQLException من نوع Unchecked.
الصواب: خطأ
5) PreparedStatement يحمي من حقن SQL.
الصواب: صح
6) Checked Exception خطأ صياغة يمنع الترجمة.
الصواب: خطأ
3السؤال الثالث: أسئلة عملية
1) تتبّع الناتج:
snippet×
SourceHistory⟲⟳🔍
class Account{privatedouble b;staticint n = 0; Account(double b) { this.b = b; n++; }void add(double x) { if (x > 0) b += x; }double get() { return b; }}publicclass Main{publicstaticvoid main(String[] args) { Account a = new Account(50); Account c = new Account(10); a.add(25); c.add(-5);System.out.println(a.get() + " " + c.get() + " " + Account.n); }}
الناتج الصحيح:Output×
75.0 10.0 2
2) تتبّع الناتج:
snippet×
SourceHistory⟲⟳🔍
abstractclass V{abstractint wheels();void info() { System.out.println(getClass().getSimpleName() + ": " + wheels()); }}class Bike extends V { int wheels() { return2; } }class Car extends V { int wheels() { return4; } }publicclass Main{publicstaticvoid main(String[] args) { V[] vs = { new Bike(), new Car() };for (V v : vs) v.info(); }}
4) اكتب كلاس Student بخاصية private اسمها mark ودالتي get و set (تقبل 0 إلى 100 فقط)، وكلاس GradStudent يرثه ويضيف خاصية thesis. أنشئ GradStudent واضبط mark = 95 واطبعها.
الحل النموذجي:
Student.java×
SourceHistory⟲⟳🔍
class Student{privatedouble mark;publicdouble getMark() { return mark; }publicvoid setMark(double mark) {if (mark >= 0 && mark <= 100) this.mark = mark;elseSystem.out.println("Invalid mark"); }}class GradStudent extends Student{String thesis;}publicclass Main{publicstaticvoid main(String[] args) { GradStudent g = new GradStudent(); g.setMark(95);System.out.println(g.getMark()); }}