تقييم الدرس 3: دالة البناء Constructor
إجاباتك تُحفظ تلقائيًّا على هذا الجهاز. أجب ثم اضغط «صحّح ورقتي» أسفل كل قسم.
← العودة إلى الدرس 3: دالة البناء Constructor · أسئلة التقييم · أكمل الفراغات
أسئلة التقييم
أسئلة تقييم الدرس: دالة البناء Constructor. إجاباتك تُحفظ تلقائيًّا على هذا الجهاز؛ أجب ثم اضغط «صحّح ورقتي».
1السؤال الأول: اختر الإجابة الصحيحة
class Test{ int a, b; public Test(){ a = 10; b = 20; } public void msg(){ System.out.println ("a = " + a + " b = " + b ); }} public class Main { public static void main(String args[]) { Test obj1 = new Test(); obj1.a += 1; obj1.b += 1; obj1.msg(); }}
class Box{ int size; Box(int s) { size = s; }} public class Main{ public static void main(String[] args) { Box b = new Box(5); System.out.println(b.size); }}
2السؤال الثاني: صح أم خطأ
3السؤال الثالث: أكمل الفراغات
1) تُستخدم الكلمة للإشارة إلى الكائن الحالي.
💡 أربعة أحرف إنجليزية، تشير إلى الكائن الحالي.
2) دالة البناء بالإنجليزية .
💡 اسم دالة البناء بالإنجليزية.
3) القيمة الافتراضية لخاصية String هي .
💡 قيمة «لا شيء» للنصوص في جافا.
4) دالة البناء بلا معاملات تُسمّى دالة البناء .
💡 الدالة التي لا تستقبل معاملات تُسمّى دالة البناء ___ .
4السؤال الرابع: التوصيل
طابِق كل عنصر في العمود (أ) بما يناسبه في العمود (ب):
- 1) Book()
- 2) Book(int id)
- 3) this.id
- 4) new
- 5) null
- أ. تستدعي دالة البناء.
- ب. قيمة نصّ لم يُعطَ قيمة.
- ج. دالة بناء بمعامل.
- د. خاصية الكائن الحالي.
- هـ. دالة بناء افتراضية.
5السؤال الخامس: أسئلة عملية
class Book { int id; String title; String author; double price; int pages; public Book(){ } public Book(int id, String title, String author, double price, int pages){ this.id = id; this.title = title; this.author = author; this.price = price; this.pages = pages; } public void printBookDetails(){ System.out.println("Book details: "); System.out.println("Id: " + id); System.out.println("Title: " + title); System.out.println("Autor: " + author); System.out.println("Price: " + price); System.out.println("Pages: " + pages); }}
class Book { int id; String title; String author; double price; int pages; public Book(){ } public Book(int id, String title, String author, double price, int pages){ this.id = id; this.title = title; this.author = author; this.price = price; this.pages = pages; } public void printBookDetails(){ System.out.println("Book details: "); System.out.println("Id: " + id); System.out.println("Title: " + title); System.out.println("Autor: " + author); System.out.println("Price: " + price); System.out.println("Pages: " + pages); }}
class Book { int id; String title; String author; double price; int pages; public Book(){ } public Book(int id, String title, String author, double price, int pages){ this.id = id; this.title = title; this.author = author; this.price = price; this.pages = pages; } public void printBookDetails(){ System.out.println("Book details: "); System.out.println("Id: " + id); System.out.println("Title: " + title); System.out.println("Autor: " + author); System.out.println("Price: " + price); System.out.println("Pages: " + pages); }}
class Book { int id; String title; String author; double price; int pages; public Book(){ } public Book(int id, String title){ this.id = id; this.title = title; } public void printBookDetails(){ System.out.println("Book details: "); System.out.println("Id: " + id); System.out.println("Title: " + title); System.out.println("Autor: " + author); System.out.println("Price: " + price); System.out.println("Pages: " + pages); }}public class Library { public static void main(String[] args) { Book book1 = new Book(); book1.id = 1; book1.title = "Effective Java"; Book book2 = new Book(2, "Java in One Day"); book1.printBookDetails(); book2.printBookDetails(); }}
5) تتبّع الناتج:
class Pen{ String color; Pen() { color = "Blue"; } Pen(String c) { color = c; }} public class Main{ public static void main(String[] args) { Pen a = new Pen(); Pen b = new Pen("Red"); System.out.println(a.color + " " + b.color); }}
6) صحّح السطر في دالة البناء حتى تُخزَّن القيمة في الخاصية:
radius = radius;this.radius = radius;أكمل الفراغات
اختر الكلمة الصحيحة من القائمة المنسدلة في كل فراغ. إجاباتك تُحفظ تلقائيًّا على هذا الجهاز؛ أجب ثم اضغط «صحّح ورقتي».
1السؤال الأول: أسئلة عملية
اكمل الكود التالي من مثال المكتبة library:
أكمل دالة البناء التي تستقبل معاملات، ثم أنشئ الكائن bk2 باستخدامها
public class Book { int id; String title; public (int id, String title) { .id = id; this.title = ; }}Book bk2 = Book(2, "Learn Javan");