Professional Documents
Culture Documents
- .alghushaimi اسئلة وحلول جافا 2020 - 2021
- .alghushaimi اسئلة وحلول جافا 2020 - 2021
1) What is the output of the below Java program with FOR loop?
2)What is the output of the below Java program with two classes?
//Testing1.java
public class Example{ }
public class Testing1
{
public static void main(String[] args) {
System.out.println("Hello Boss.!") }
options:
Hello Boss.! B) No Output C) Compiler error. D) None of the above
//bingo.java file
A) 1 2 3 4 5 6 7 8 9 10 C) i j k l m n o p q r
B) 0 1 2 3 4 5 6 7 8 9 10 D) i i i i i i i i i i
1/6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
9) What is the type of variable ‘b’ and ‘d’ in the below snippet?
int a[], b;
int []c, d;
options:
A) b’ and ‘d’ are int. B) b’ and ‘d’ are arrays of type int
C) ‘b’ is int variable; ‘d’ is int array D) ‘d’ is int variable; ‘b’ is int array
10) a class can extends --------- class(es) , An interface can extends ------
-- interface(es)
Options:-
A) single/single B)single/multiple C) multiple/single D) multiple/multiple
2/6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
11) What is the output of the below Java program that passes an object to
another method?
class Food
{
int items; int show()
{return items;}
}
class Testing
{
public static void main(String[] args)
{
Food f = new Food(); f.items = 5;
System.out.println("Items Before = " + f.show()); change(f);
System.out.println("Items After = " + f.show()) } static void change(Food
foo)
{ foo.items = 10; }
A) B)
Items Before = 10 Items Before = 5
Items After = 10 Items After = 5 .
C) D)
Items Before = 5 Items Before = 10
Items After = 10 Items After = 5
12) What is the output of the Java program with Enhanced FOR loop below?
A) BRAZIL,CHILE,SYDNEY, B) BRAZIL,CHILE,
3/6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
13-What is the output of the below Java program with a final local variable?
public class TestingMethods8
{ int cars = 20;
void change(final int cars) {
cars = 10;
this.cars = cars; }
public static void main(String[] args) {
TestingMethods8 t8 = new TestingMethods8();
t8.change(30);
System.out.println(t8.cars); } }
Options:-
A) 30 B) 20 C) 10 D ) Compiler error
14) What is the output of the below Java program with arrays?
16) What is the process of defining a method in a subclass having same name &
type signature as a method in its superclass?
A) Method overloading B) Method overriding
C) Method hiding D) None of the mentioned
A) super(void) . B) superclass () .
C) super A() . D) super() .
4/6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
class comma_operator
{
public static void main(String args[])
{
int sum = 0;
for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
sum += i;
System.out.println(sum);
}}
options:
A) 5 B) 6 C)14 D) compilation error
A) 8 B) 9 C) 10 D)11
5/6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
25) A constructor can call another overloaded constructor using the ___ keyword in Java.
26) ---------------- is the superclass to all Java classes either user-defined or built-in.
A) Class B) Object c) Superclass D) Null
27) a class can extends --------- class(es) , An interface can implements --------
interface(es)
A)single/sinle B)single/multiple C) multiple/single D) multiple/multiple
28) خيار واثنين أسئلة مباشرة فقط يعني هناك سؤال واحد فقط لم استطع تذكره28 لكن التقلق عدد أسئلة الخيارات هي لم استطع تذكره اظن انه سؤال كان لمصفوفة ذات بعدين
6/6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
29) Find, enumerate, and explain the errors in the following program:(the line help you
explain)
return true; }
1--------------------------------------------------------------------------------------------------------------------------------------------------
2--------------------------------------------------------------------------------------------------------------------------------------------------
3--------------------------------------------------------------------------------------------------------------------------------------------------
4--------------------------------------------------------------------------------------------------------------------------------------------------
5--------------------------------------------------------------------------------------------------------------------------------------------------
6--------------------------------------------------------------------------------------------------------------------------------------------------
7--------------------------------------------------------------------------------------------------------------------------------------------------
8--------------------------------------------------------------------------------------------------------------------------------------------------
9--------------------------------------------------------------------------------------------------------------------------------------------------
30- Write a Java method intSumDigit that take in an integer n and returns the sum
of all its digits.
(for instance (1234)<..1+2+3+4..>=12)
ﺍﻷﺳﺌﻠﺔاالخرين في نفس دفتر األسئلة لذلك كان من طبعا كان إجابة ﺟﻤﻴﻊ
السؤالين
وهذة األسئلة الذي هي جميع أسئلة. المستحيل ان نخرج ورقة األسئلة
االختباراال سؤال انما حاولت استذكرها وقمت بتجميعها وترتيبها ومن ثم
.أمال ان تنتفعوا بذلك .حلها كامال في النهاية
لم يكن الهدف ابدا ان تحفظوا األسئلة النه ببساطة نحن ندرس لنتعلم وأيضا
ربما لن يكرر الدكتور أي سؤال من االختبار لهذا العام
انما كان بمثابة مساعدة لك لتقيس مدى فهمك وتذاكر اكثر و اكثر وتكون.
وهللا الموفق.مطمئنا عندما ترى بساطة األسئلة
7/6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
1 (A) A) 1,2,3,4,
--------------------------------------------------------
2 (C) Compiler error ( في نفس الملفclass ( الكثر منpublic ) نالحظ وجود
( داخل ملف واحد في الجافاpublic class) رغم انه ال يمكن انشاء اكثر
--------------------------------------------------------
3 (C) Compiler error (class) يجب ان يكون اسم الملف للجافا مثل اسم
------------------------------------------
4 (D) i i i i i i i i i i
--------------------------------------------
5 (D) Compiler error
--------------------------------------------------------
6 (A) 0 2 4 6 8
--------------------------------------------------------
7 (A) It is necessary to use new operator to initialize an array اإلجابة الخطأ من الخيارات هي
--------------------------------------------------------
8 (A) Row.
--------------------------------------------------------
9 (C) ‘b’ is int variable; ‘d’ is int array
--------------------------------------------------------
10 (B) single/multiple
--------------------------------------------------------
11 (C)Items Before = 5 Items After = 10
--------------------------------------------------------
12 (B) BRAZIL,CHILE,
--------------------------------------------------------
13 (D) Compiler error( تسبب حدوث خطأcars *= 10; بعد إعطائه قيمة لذلكfinal ال يمكن تغيير قيمة المتغير من النوع
--------------------------------------------------------
14 (B) PLANE
--------------------------------------------------------
15 (D) int arr[] = int [5] new
--------------------------------------------------------
16(B) Method overriding
8/6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
--------------------------------------------------------
17(D) final
--------------------------------------------------------
;)(18(D) super
--------------------------------------------------------
19(B) 6
--------------------------------------------------------
20(D) 1
--------------------------------------------------------
21(B) 9
--------------------------------------------------------
22(B) 10
--------------------------------------------------------
23(A) Garbage value
--------------------------------------------------------
24(D) All the above
--------------------------------------------------------
25(A) this
--------------------------------------------------------
26( B) Object
--------------------------------------------------------
27(B) Single/multiple
--------------------------------------------------------
) (28
كما قلت مسبقا عدد الخيارات 28هناك خيار لألسف لم استطع تذكره اظن كان السؤال لمصفوفة ذات بعدين
ابضا الخيار رقم 23 & 1ال أتذكر جيدا انه من ضمن الخيارات او
كانت أسئلة اخرى
؏
*
؏
تجميع وحلول
عبدالرحمن الغشيمي
؏ 2021/8/24
؏
*
؏ 9/6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
print(arr); } او يجب ال يمكن استدعاء الدالة بشكل مباشر اذا لم تكن
ومن ثم استدعائها باستخدامclass echo منobject انشاء
void print(String[] greetings) {
dot opretor
for (int i = 0; i <= args.length; i++) Greeting < args نستبدل
=ونحذف إشارة المساواة
System.on.print(greetings[i] + " ");
out بon نستبدل
------------------------------------------------------------
}}
10 /
6
Electrical Engineering Dept.
Programming Languages III – Java Control & Computer Section
Final Exam 2020/2021 – 4th year - 2nd Term
عبدالرحمن الغشيمي
import java.util.Scanner;
public class SumDigit
{
static int intSumDigit(int n){
int sum=0;
while(n ! 0) {
sum += n % 10;
n /= 10; }//end while loop
return sum; }//end function intSumDigit
public static void main(String args[])
{
int number;
أخيرا نرجوا منكم
System.out.println("please inter integer number"); المسامحة اين
Scanner input = new Scanner(System.in); وجدتم أخطاء
number=input.nextInt(); فالكمال هلل وحده
System.out.println( "sum of digit for "+number +" is " +intSumDigit(number));
}}
مالحظات يجب عليك العيش مع المادة اكثر مدة ممكنة اجعل عندك الشغف لتعلمها فهي
.حقا ممتعة
.string بالنسبة ألسئلة االختبار الدكتور اكثر تركيزه على المصفوفات ثم
باإلمكان البحث عن هذه األسئلة لمعرفة.اطلعوا على تمارين من المواقع المشهورة
. المواقع