Java 1 Full Revision
Java 1 Full Revision
JAVA Revision
344 Questions
تحذير هام
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
JAVA Midterm 1
26 Questions
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
I. Multiple Choice Questions / T & F
1|Page www.MoussaAcademy.com
00201007153601
7. The methods in Java class libraries are known as methods.
A. User-defined
B. Library-defined
C. Pre-defined
D. Parameter
8. A/ An is a collection of classes with a related purpose.
A. Interface
B. Package
C. JVM
D. Container
9. The informal language written in plain English that described the step by step of a problem’s
solution.
A. Program
B. Pseudocode
C. Compiler
D. Instruction
10. Which statement declares a variable that will store a floating-point number ?
A. floating x;
B. double x;
C. 5.1 = x;
D. String x = 5.6;
11. If x and y are int types variables, what will be the result of the expression x/y when x=9 and y=2?
A. 4.5;
B. 4
C. 4.25
D. 4.75
12. The following Java statement has .
System.out.println(“Welcome! To Object oriented exam”)
A. Multiple errors
B. No error
C. A syntax error
D. A run time error
13. What is the output of the following code snippet?
String output = 5 >= 100? “Yes” : “No”;
System.out.print(output);
A. output
B. Yes
C. No
D. 100
2|Page www.MoussaAcademy.com
00201007153601
14. What is the output of the following code snippet?
int number = 2;
switch(number) {
case 1: System.out.print(“First “);
break;
case 2: System.out.print(“Second “);
case 3: System.out.print(“Third “);
break;
default: System.out.print(“Fourth “);
}
A. Second
B. Second Third
C. Second Third Fourth
D. Syntax Error
15. What is the output of the following code snippet?
int x = 3, y = 10;
if (x > 7)
if(x > 7)
if(x > 7)
System.out.println(“y is > 7”);
else
System.out.println(“x <= 7”);
System.out.println(“x is < 7”);
A. y is > 7
B. x is <= 7
C. x is < 7
D. Syntax error
16. What is the output of the following code snippet?
if(10%2 == 0)
System.out.print(“Even “);
else
System.out.print(“Odd “);
System.out.println(“Number”);
A. Even Number
B. Odd Number
C. Number
D. No output because there is no semicolon at the end of the if statement
17. Which of the following class name is correct?
A. Student@
B. Student5
C. Student&
D. 5Student
3|Page www.MoussaAcademy.com
00201007153601
18. A is a location in the computer’s memory where values can be stored for user later in a program.
A. variable
B. class
C. package
D. method
19. A class is used to read an input given by a user.
A. Socket
B. Stream
C. Stack
D. Scanner
20. allows you to trace and remove bugs, errors, and abnormalities from your programs.
A. Editing
B. Troubleshooting
C. Debugging
D. Checking
21. What is the output of the following code snippet?
int counter;
for(counter = 1; counter <= 10; counter++) {
if(counter ==3) {
break;
}
}
System.out.println(“ the counter value is “ + counter);
A. The counter value is 1
B. The counter value is 10
C. The counter value is 3
D. The counter value is 11
4|Page www.MoussaAcademy.com
00201007153601
22. What is the output of the following code snippet?
String gender = "male";
int age = 22;
if(gender == "male" && age > 25) {
System.out.println("First if statement.");
} else if( gender == "female" || age > 25) {
System.out.println("Second if statement.");
} else if ( gender =="male" ^ age == 22) {
System.out.println("Third if statement.");
} else if(gender == "female" || age != 23) {
System.out.println("Fourth statement.");
}
A. First if statement.
B. Second if statement.
C. Third if statement.
D. Fourth if statement.
23. What is the output of the following code snippet?
int n = 1;
do {
System.out.printf("%d ", n);
n+=2;
} while (n <= 5);
System.out.println();
A. 1 2 3 4 5
B. 2 4 5
C. 1 3
D. 1 3 5
24. If a loop exists inside the body of another loop, it’s called a .
A. Static loop
B. nested loop
C. while loop
D. dynamic loop
5|Page www.MoussaAcademy.com
00201007153601
II. Open Questions
25. Write a complete java program that performs the following tasks:
A. Ask the user to enter a positive number of his/her total mark. If the user enters a negative number, then
the program keeps running asking the user to enter the total mark.
B. Once the user enters a positive number, print the student’s grade based on the obtained mark as the
following
a. If the student’s mark is greater than or equal to 60, print “Passed”.
b. If it is not, print “Failed”.
import java.util.Scanner;
6|Page www.MoussaAcademy.com
00201007153601
26. Find the output of the following Java program:
public class main {
public static void main( string[] args)
{
System.out.println(“hello!”);
int a = 3, b = 1, c = 2;
a = ++b;
int max = Math.max(c,3);
System.out.println(“a: “, a);
System.out.println(“b: “, b);
System.out.println(“max: “, max);
int result = getResult(max);
System.out.println(“result: “, result);
}
public static int getResult(int m) {
return m * m *m;
}
}
hello!
a: 2
b: 2
max: 3
result: 27
7|Page www.MoussaAcademy.com
00201007153601
JAVA Midterm 2
27 Questions
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
I. Multiple Choice Questions
1. Which of the following components transforms bytecode into machine specific code?
a) JKI
b) JVM
c) JRE
d) JTI
2. To display multiple lines of text with a single statement, the special escape character
a) \n
b) \r
c) \**
d) \\
if (1>3)
System.out.println("Hello");
System.out.println("World");
a) World
b) Hello
World
c) Hello
d) There is no output due to compilation errors
a) 10*2-0
b) 20-1
c) 10*2-1
d) 20-0
1|Page www.MoussaAcademy.com
00201007153601
6. To embed program documentation directly into java programs we use____________
a) //
b) ./
c) /** and */
d) %* and*%
7. You would use ___________ to repeat a block of codes for several known times.
a) if statements
b) for loops
c) java classes
d) switch
a) TRUE: FALSE
b) Run time error
c) FALSE
d) TRUE
a) 5
b) 4
c) 0
d) 6
2|Page www.MoussaAcademy.com
00201007153601
10. What is the output of the following code snippet if the input is 25?
int i;
Scanner in = new Scanner(System.in);
System.out.print("Enter number ? ");
i = in.nextInt();
if(i > 25){
i++;
} else{
i--;
}
System.out.print(i);
a) 26
b) 24
c) 25
d) 27
11. The main functionality of _____________ is to convert high-level language programs into machine
language.
a) Memory handlers
b) Assembly language
c) Compiler
d) Machine language
a) False
b) The code has run time error
c) True
d) The code has a syntax error
3|Page www.MoussaAcademy.com
00201007153601
13. What is the output of the following code snippet?
double income = 6000;
double cutoff = 5000;
double minIncome = 3000;
if(minIncome > income){
System.out.println("Minimum income requirement is not met.");
}
if(cutoff < income){
System.out.println("Maximum income limit is exceeded.");
}
else {
System.out.println("Income requirement is met.");
}
a) There’s no output
b) Maximum income limit is exceeded
c) Income requirement is met
d) Minimum income requirement is not met
15. Which of the following statement declares a variable that will store an integer value?
a) String count = 5;
b) count = 5;
c) integer count
d) int count;
16. ___________ is a procedure for solving a problem in terms of the actions to execute and the order is
which they execute.
a) Firmware program
b) Hardware program
c) Algorithm
d) Software bug
4|Page www.MoussaAcademy.com
00201007153601
17. What is the output of the following java code?
public class A {
public static void main(String[] args) {
int I = 24;
String S = "Hello";
System.out.println("%d %s", I, S);
}
}
a) 24 Hello
b) 23
c) Hello
d) I S
18. When a Java program is compiled, the compiler creates a file that has the file extension.
a) .txt
b) .js
c) .java
d) .class
19. Any computer would understand only its own machine language, which is known as machine _______
a) dependent
b) independent
c) shared
d) isolated
5|Page www.MoussaAcademy.com
00201007153601
20. What is the output of the following java code:
public class A {
public static void main(String[] args) {
char grade = 'L';
switch (grade) {
case 'A':
System.out.println("Excellent!");
break;
case 'B':
case 'C':
System.out.println("Well done");
break;
case 'D':
System.out.println("You passed");
break;
case 'F':
System.out.println("Better try again");
break;
default:
System.out.println("Invalid grade");
}
}
}
a) Well done
b) Great
c) Invalid grade
d) Excellent!
a) 10
b) 20
c) no output
d) compile-time error
6|Page www.MoussaAcademy.com
00201007153601
22. In java each statement ends with
a) :
b) ;
c) )
d) }
23. A/an ____________ would be used to have a loop that is inside another loop.
a) nested if statement
b) nested loop
c) if statement
d) method
a) True
b) FALSE Statement
c) False
d) TRUE Statement
7|Page www.MoussaAcademy.com
00201007153601
II. Essay Questions
a. Asks the user to give his/her name and store it in a variable name.
c. Find and print the even numbers from 2 to number using for loop.
import java.util.Scanner;
8|Page www.MoussaAcademy.com
00201007153601
2. Find the output of the following Java Program?
public class TestMidTerm {
public static void main(String[] args) {
System.out.println("Hello");
int sum = 0;
for (int i = 1; i < 2; i++) {
sum = sum + i;
for (int z = 0; z <= 1; z++) {
System.out.println("i= " + i + " .. z= " + z);
}
}
System.out.println("sum = " + sum);
System.out.println("End!");
}
}
Hello
i= 1 .. z= 0
i= 1 .. z= 1
sum = 1
End!
9|Page www.MoussaAcademy.com
00201007153601
JAVA Midterm 3
60 Questions
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
I. Questions and Answers
Answer: D
Explanation: A: nextInt(), B: nextDouble(), C: nextLine() but next() takes first token only (stops until it first
space).
Answer: C
Explanation: A,B,C are not key words of java
1|Page www.MoussaAcademy.com
00201007153601
Answer: A
Explanation: x < 5 || x > 10 means x < 5 or x > 10, so anything less than 5 is TRUE, 4 < 5 YES.
and OR (||) only requires one of the two statements to be true in order to be true.
Answer: A
Explanation: in switch-case with break statement is like if-condition, only ONE condition (case) is executed
when break statement is used, here, the char ‘x’ has value ‘+’, so the first case is executed, n1+n2 = 10 + 15 = 25
2|Page www.MoussaAcademy.com
00201007153601
Answer: D
Explanation: A: type of java edition, B: JRE is Java Runtime Environment, the development libraries and
classes C: JVM is the Java Virtual Machine, where java bytecodes are run
3|Page www.MoussaAcademy.com
00201007153601
Answer: D
Explanation:
Semantic error: errors due to meaning/context
Math error: errors due to math operations like division by zero
Logic error: errors due to incorrect program flow/number results (like incorrrect sum)
Syntax error: errors due to wrong rules in typing of language code (like semicolon;)
= is used for assignment
== is used for comparison
Answer: C
Explanation:
break: exit loop forcefully
return: end of function
exit(): function to quit current executing program
4|Page www.MoussaAcademy.com
00201007153601
Answer: C
Explanation: 2/10 is 0 (integer division) which is greater than 0
Answer: D
Explanation: A and C are error (int and double)
B will take only first name, we need to take the full name (all of the line)
5|Page www.MoussaAcademy.com
00201007153601
Answer: D
Answer: A
6|Page www.MoussaAcademy.com
00201007153601
Answer: B
Explanation: The loop will run as follows:
at i = 0, check 0==4, NO print 0
at i = 1, check 1==4, NO print 1
at i = 2, check 2==4, NO print 2
at i = 3, check 3==4, NO print 3
at i = 4, check 4==4, YES BREAK (leave loop entirely)
Answer: C
Explanation: Selection statement are statements that select a certain execution/program flow/code block
depending on a condition, so we choose IF-ELSE or SWITCH-CASE
7|Page www.MoussaAcademy.com
00201007153601
Answer: B
Answer: A
Answer: B
Explanation: \” escape character for “ and \n prints new line
8|Page www.MoussaAcademy.com
00201007153601
Answer: D
Answer: D
Explanation: number % 2 returns remainder of division by 2, so if remainder is zero (==0), then this number
must be even, it is a very common code snippet used, hence, we choose D
9|Page www.MoussaAcademy.com
00201007153601
Answer: C
Explanation:
10 | P a g e www.MoussaAcademy.com
00201007153601
Answer: A
Answer: D
Explanation:
[ ] Printed normally
%60 means reserve 60 spaces
S means print the string to come in UPPER CASE
Answer: D
11 | P a g e www.MoussaAcademy.com
00201007153601
Answer: C
Answer: A
12 | P a g e www.MoussaAcademy.com
00201007153601
Answer: C
Answer: B
Explanation: It has the ordering wrong, it should bne cost = 72 not the other way around. Also, the
variable name is incorrect to begin with, variables cannot start with digits
Ansswer: B
13 | P a g e www.MoussaAcademy.com
00201007153601
Answer: B
Answer: C
Answer: B
Explanation: A: cannot start with number
C: Cannot have special symbol *
D_:cannot have spaces
14 | P a g e www.MoussaAcademy.com
00201007153601
Answer: C
Answer: C
Answer: A
15 | P a g e www.MoussaAcademy.com
00201007153601
Explanation:
%s first string: “1”
! printed normally
%s for second string: “234”
%n for new line (like \n)
%s for third string “6767”
%n for new line (not visible because end of code)
Answer: A
Explanation: Runtime errors are errors that stop the program only during its running (runtime) and does not
prevent compilation.
Answer: D
Answer: A
16 | P a g e www.MoussaAcademy.com
00201007153601
Answer: C
Answer: C
17 | P a g e www.MoussaAcademy.com
00201007153601
False
True
True
False
C
A
B
D
T
T
B
B
A
F
B
D
T
F
F
JAVA Midterm 4
29 Questions
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
I. Multiple Choice Questions
1. Which package in Java provides classes and Interfaces for data structures like lists, sets, and maps?
a) java.net
b) java.io
c) java.util
d) java.lang
4. The method name should be a ___________ and start with a ___________ letter.
a) Verb / Uppercase
b) Noun / Lowercase
c) Adjective / Uppercase
d) Verb / Lowercase
1|Page www.MoussaAcademy.com
6. Which of the following statements is true about Java API packages?
a) Java API packages provide a collection of classes and interfaces for various programming tasks.
b) Java API packages can't be used for creating custom applications.
c) Java API packages are only used for internal purposes and cannot be accessed by developers.
d) Java API packages are specific to a particular IDE and cannot be used in other Java environments
a) y is the smallest
b) 65
c) 60
d) x is the smallest
2|Page www.MoussaAcademy.com
10. Which of the following is not a valid example of method overloading for display method?
a) public int display(int num)
b) public void display(int num1, int num2)
c) public void display(String str)
d) public void display(int num)
11. Which package in Java provides classes and Interfaces for basic input/output operations?
a) java.util
b) java.lang
c) java.net
d) java.io
12. One of the following is Invalid Identifier (e.g. user defined variable) in Java programming language.
a) Welcome1
b) $welcome_
c) 1welcome_
d) _welcome1
3|Page www.MoussaAcademy.com
15. sqrt() is a ____________ method of Math class. It returns the square root of a number.
a) Predefined
b) Modified
c) User-defined
d) Customized
16. What is the return type of a method that does not return any value?
a) double
b) void
c) float d
d) int
17. To calculate the maximum number of two variables x and y, we can use the following java statement:
a) Math.maximum(x,y);
b) Math.max(x,y);
c) x.Math maximum(y)
d) y.Math.max(x)
18. The procedure of solving a problem in regards to action and sequence order called_______________.
a) Java Code
b) Algorithm
c) Program
d) Pseudocode
19. In Java, an expression of a switch statement must be one of the following types.
a) Byte, short, int, long, enums and string
b) int, float, double
c) int, short, byte, double
d) String, float, double
4|Page www.MoussaAcademy.com
21. The Escape Sequence ____________ is used to print double-quote (") inside print statement.
a) q\
b) \”
c) \Esc
d) \q
22. A/An ______________ Is a location in the computer's memory where a value can be stored for later
uses in a program
a) Input
b) Method
c) Scanner
d) Variable
24. In Java, _______________ executes a block of code if a condition is true, but if false it executes another
block of code.
a) If statement
b) Continue statement
c) If... else statement
d) Switch statement
26. To read Input from the keyboard (e.g. from the user), we have to create and use a/an _______ object.
a) Integer
b) Variable
c) Input
d) Scanner
5|Page www.MoussaAcademy.com
27. The ____________ Is the routine process of locating and removing bugs, errors or abnormalities from
programs.
a) Commenting
b) Debugging
c) Compiling
d) Declaration
28. Using for loop write Java code that display the following:
Output example:
SEU-1
SEU-2
SEU-3
6|Page www.MoussaAcademy.com
29. Solve the following.
a. Write a complete program to calculate and print the value of the following
algebraic expressions:
x=6
y = 254
z = 28.0
7|Page www.MoussaAcademy.com
JAVA Final 2021
29 Questions
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
IT232 Final Fall 2021
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
1|Page www.MoussaAcademy.com
00201007153601
College of Computing and Informatics
RM
Paper Information
Object Oriented
Course Title: Programming Course Code: IT232
Number of Pages:
(including cover
Exam Duration: 120 Minutes page) 16
Student Details
Student
Student Name: ID:
Instructor
CRN: :
Branch:
Exam Instructions
• Fill the above ‘Student Details’ section carefully and complete.
• You are advised to count the number of pages and compare to the number written
above.
• Electronic devices are NOT permitted. Turn off your electronic devices and put
them in the plastic bag under your seat.
• Put your ID card on your desk with your photo face up.
• Use Blue-color pen only.
• You are not allowed to leave the examination room during the first 30 minutes of
the start of Examination.
• Cheating is strictly prohibited and action will be taken.
1
ti
College of Computing and Informatics
RM
Q1.1
Q1 /25 LO1 ⬜ Yes ⬜ No
Q1.13
Q2 /10 LO2 ⬜ Yes ⬜ No
Q1.8
Q3 /15 LO3 ⬜ Yes ⬜ No
Final Q1.23
Score:
/ 50 LO4 ⬜ Yes ⬜ No
Q1.2
LO5 ⬜ Yes ⬜ No
1) Circle ONE correct answer for each of the following MCQs in the table below.
Actual
Score
1 2 3 4 5 6 7 8 9 10
25
a a a a a a a a a a
b b b b b b b b b b
c c c c c c c c c c
d d d d d d d d d d
11 12 13 14 15 16 17 18 19 20
a a a a a a a a a a
b b b b b b b b b b
c c c c c c c c c c
d d d d d d d d d d
21 22 23 24 25
a a a a a
b b b b b
IT232 2
College of Computing and Informatics
RM
c c c c c
d d d d d
2. Complete the following code snippet with the correct enhanced for loop so it iterates
over the array without using an index variable. (LO5) (Nahlah Algethami) [6].
int [] evenNo = {2,4,6,8,10};
___________________
System.out.print(e+" ");
3. What is the output of the following Java code? (LO4,LO5) (Nahlah Algethami) [6].
int []myArray = new int [5];
for(int i=0; i< myArray.length; i++)
{
if(i%2 ==0)
myArray[i] = i+1;
System.out.print(" "+myArray[i]);
}
a. 1 0 3 0 5
b. 1 2 3 4 5
c. 0 0 0 0 0
d. 1 0 0 0 0
4. If class Student is subclassed from class Person then which is the correct syntax? (LO5)
IT232 3
College of Computing and Informatics
RM
5. Find Superclass and Subclass in the below Java code snippet? (LO5) (Nahlah Algethami)
[Week 12].
class B
{
void show(){}
}
class A
{
void hide(){}
}
a. B is superclass and A is subclass
b. A is superclass and B is a subclass
c. There is no superclass or subclass present
d. A is subclass and there is no superclass
6. When we compile Hello.java file, the _____ produces a _________ file. (LO1) (Nahlah
Algethami) [chapter 1].
a. Compiler, Hello.class
b. Interpreter, Hello.java
c. Debugger, Hello.exe
d. Class, Hello.class
7. Which polymorphism behavior do you see in below class? (LO1) (Nahlah Algethami)
[Week 12].
class Draw{
public void Color(int x) { }
public void Color(int x, int y) { }
public void Color(int x, int y, int z) { }
}
a. Method overloading
IT232 4
College of Computing and Informatics
RM
b. Constructor overloading
c. Method overriding
d. Upcasting
8. What is the output of the following Java code? (LO3, LO4, LO5) (Nahlah Algethami)
[chapter 4].
int i = 0;
for(i = 0; i < 10; i++){
break;
}
System.out.println(i);
a. 1
b. 0
c. 10
d. 9
9. What is the output of the following Java code? (LO4, LO5) (Nahlah Algethami) [chapter
5].
public class Test{
public static int sum(int a){
return a +5;}
public static int sum(int a, int b){
return a+10;
}
a. 6 10
b. 6 15
c. 11 15
d. 1 5
IT232 5
10. What will be the value inside the variables x and y after the given set of assignments?
(LO1) (Dr Mohd Uruj Jaleel) [Chapter Number 2 ] Week 4
int x = 20;
int y = 10;
x = (x - y) * 2;
y = x / 2;
a. x = 40, y = 20
b. x = 20, y = 10
c. x = 10, y = 20
d. x = 20, y = 20
11. What is the printed value of x? (LO1) (Dr Mohd Uruj Jaleel) [Chapter Number 4]
Week 6
int x = 6;
for(int i = 5 ; i>1; i --)
x --;
System.out.println(x);
a. 2
b. 1
c. 0
d. No value of x will be printed because the loop will never stop
12. Which of these keywords is used to prevent content of a variable from being
modified? (LO1) (Dr Mohd Uruj Jaleel) [Chapter Number 8 ] Week 11
a. final
b. last
c. constant
d. static
13. Which of the following is the correct way of importing an entire package ‘pack’?
(LO2) (Dr Mohd Uruj Jaleel) [Chapter Number 8] Week 11
IT232 6
College of Computing and Informatics
RM
a. import pack.;
b. Import pack.;
c. import pack.*;
d. Import pack.*;
14. What will be the output of the following Java code? (LO1) (Dr Mohd Uruj Jaleel)
[Chapter Number 5 ] Week 7
class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a, int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6);
System.out.println(obj.x);
}
}
a. 5
b. 6
c. 7
IT232 7
College of Computing and Informatics
RM
d. 8
15. A ____________ is needed to terminate recursion. (LO1) (Dr Mohd Uruj Jaleel)
[Chapter Number 18] Week 14
a. recursion step
b. break statement
c. void return type
d. base case
16. Which component is responsible for conver ng bytecode into machine speci c code?
(LO1) (Afra Alrubaiaan) [Chapter 2]
a. JVM
b. JDK
c. JIT
d. JRE
17. Find the output of the given Java program? (LO1) (Afra Alrubaiaan) [Chapter 3]
public class Main
{
public static void main(String[] args) {
boolean x, y, z;
x = y = z = true;
IT232 8
ti
fi
College of Computing and Informatics
RM
18. Each class you create becomes a new ________ that can be used to declare variables
and create objects. (LO2) (Afra Alrubaiaan) [Chapter 7]
a. package
b. instance
c. library
d. type
a. zero
b. null
c. their default values
d. false
21. Java requires a ________ call for every object that's created. (LO2) (Afra Alrubaiaan)
[Chapter 7]
a. Constructor
b. destructor
c. parameterless
IT232 9
fi
ti
College of Computing and Informatics
RM
d. parameterized
22. Indicate the result of comparing the rst string: "Apples", with the second string:
"Oranges". (LO1) (Afra Alrubaiaan) [Chapter 14]
a. less than
b. equal
c. greater than
d. true
23. Which of these methods of String class is used to obtain character at speci ed index?
(LO4) (Afra Alrubaiaan) [Chapter 14]
a. char()
b. Charat()
c. charat()
d. charAt()
24. Which of these methods of String class can be used to test two strings for equality?
(LO4) (Afra Alrubaiaan) [Chapter 14]
a. isequal()
b. isequals()
c. equal()
d. equals()
IT232 10
fi
fi
College of Computing and Informatics
RM
25. What will be the output of the following Java program? (LO5) (Afra Alrubaiaan)
[Chapter 14]
class string_class
{
public static void main(String args[])
{
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
obj2 = " world";
System.out.println(obj + " " + obj2);
}
}
a. hello hello
b. world world
c. hello world
d. world hello
[25 Marks]
IT232 11
College of Computing and Informatics
RM
2) For each ques on, circle True (T) or False (F) as appropriate.
Actual
Score
10
IT232 12
ti
College of Computing and Informatics
RM
[10 Marks]
IT232 13
ti
tt
tt
fi
ft
ti
ti
fi
College of Computing and Informatics
RM
15
a) What is the output of the following Java code?
(LO4,LO5) (Nahlah Algethami) [Week 12].
class Vehicle{
void display(){
System.out.println(" brand: "+brand +" color:
"+color + " year: "+year);}
void stop(){
System.out.println(" Car stopped moving");}
}
IT232 14
ti
College of Computing and Informatics
RM
c.stop();
}
}
[3 Marks]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b) Write a complete java program that perform the following tasks: (LO 4) [Nahlah
Algethami] [6]
•
Declare and ini alize an array of int numbers with the following elements
10,11,12,13,14,15
• Calculate and print the sum of odd and even numbers of the array.
Answer for the Marking Criteria
[3 Marks]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c) Write a complete java program that perform the following tasks: (LO5) (Afra
IT232 15
)
ti
g
g
;
;
;
)
]
College of Computing and Informatics
RM
•
Asks the user to input two strings.
•
Uses the method compareTo of the class String to compare the two strings
input by the user. Output whether the rst string is less than, equal to or
greater than the second.
Answer for the Marking Criteria
[3 Marks]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
d) Find the output of the following code: (LO5) (Dr Mohd Uruj Jaleel) [Chapter Number
8] Week 11
class Demo{
int value1;
int value2;
Demo(){
value1 = 1;
value2 = 2;
System.out.println("Inside 1st Constructor");
}
Demo(int a){
value1 = a;
System.out.println("Inside 2nd Constructor");
}
Demo(int a,int b){
IT232 16
ti
ti
fi
fi
fi
fi
College of Computing and Informatics
RM
value1 = a;
value2 = b;
System.out.println("Inside 3rd Constructor");
}
public void display(){
System.out.println("Value1 === "+value1);
System.out.println("Value2 === "+value2);
}
public static void main(String args[]){
Demo d1 = new Demo();
Demo d2 = new Demo(3);
Demo d3 = new Demo(3,4);
d1.display();
d2.display();
d3.display();
}
}
Answer for the Marking Criteria
Inside 1st Constructo [0.5 Mark]
Inside 2nd Constructo [0.5 Mark]
Inside 3rd Constructo [0.5 Mark]
Value1 === [0.25 Mark]
Value2 === [0.25 Mark
Value1 === [0.25 Mark]
Value2 === [0.25 Mark]
Value1 === [0.25 Mark]
Value2 === [0.25 Mark
[3 Marks]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
e) Write a complete java program that perform the following tasks: (LO4) (Dr Mohd Uruj
Jaleel) [Chapter Number 18] Week14
• Asks the user to input a posi ve number. If the user enters a nega ve
number, then the program keeps asking for a posi ve one.
• Find out and print the factorial of the given number.
Note: factorial of 5 is equal to: 5*4*3*2*1 = 120
IT232 17
2
1
4
3
0
3
ti
r
r
r
ti
]
]
ti
College of Computing and Informatics
RM
int f = fact(num);
System.out.println("Factorial of entered number is: " + f); [0.5 mark]
second method
import java.util.Scanner;
class FactorialDemo{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in); [0.5 mark]
int num;
do
{
System.out.println("Enter a positive number:");
num = scanner.nextInt(); [1 Mark]
}while(num<0);
f =1;
for(int i =1;i<=num;i++)
f = f * i; [1.5 Mark]
System.out.println("Factorial of entered number is: " + f);
}
[3 Marks]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IT232 18
College of Computing and Informatics
RM
IT232 19
JAVA Final 2022
73 Questions
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
Revision 73 CS140-IT232-
Questions & Answers
DS140-CS230-
IT401
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
I. Questions
1. If a class does not define constructors, the compiler provides a default constructor with no
parameters, and the class's instance variables are initialized to ________.
a) Zero
b) Null
c) Their default values.
d) False
4. Instance variables that are object references are initialized to what default value?
a) Empty
b) Instance variables are not initialized to a default value.
c) Null
d) Nil
1|Page www.MoussaAcademy.com
00201007153601
7. A correct constructor header for the Student class is:
a) public StudentConstructor()
b) public Student()
c) public void Student()
d) private int Student()
2|Page www.MoussaAcademy.com
00201007153601
11. Overriding a method differs from overloading a method because:
a) Overloaded methods have the same signature.
b) Overridden methods have the same signature.
c) Both of the above.
d) Neither of the above.
a) hello a
b) hello b hello a
c) hello c
d) hello b
14. Java constructor overloading is a technique in which a class can have _________ constructor(s).
a) two
b) one
c) three
d) any number of
3|Page www.MoussaAcademy.com
00201007153601
15. What is the process of defining two or more methods within same class that have same name but
different parameters declaration?
a) method overloading
b) method overriding
c) method hiding
d) none of the mentioned
4|Page www.MoussaAcademy.com
00201007153601
18. What will be the output of the following Java code?
class overload {
int x; int y;
void add(int a){
x = a + 1;
}
void add(int a , int b){
x = a + 2;
}}
class Overload_methods {
public static void main(String args[]){
overload obj = new overload();
int a = 0;
obj.add(6, 7);
System.out.println(obj.x);
}
}
a) 6
b) 7
c) 8
d) 9
5|Page www.MoussaAcademy.com
00201007153601
b) 6.4 6.4
c) 6.4 6
d) 4 6.4
6|Page www.MoussaAcademy.com
00201007153601
22. If a variable is declared as private, then it can be used in_________.
a) Any class of any package.
b) Any class of same package.
c) Only in the same class.
d) Only subclass in that package.
25. What will be the output of the following Java code snippet?
enum Levels {
private TOP, public MEDIUM, protected BOTTOM;
}
a) Runtime Error
b) EnumNotDefined Exception
c) It runs successfully
d) Compilation Error
7|Page www.MoussaAcademy.com
00201007153601
26. Which among the following best describes constructor overloading?
a) Defining one constructor in each class of a program
b) Defining more than one constructor in single class
c) Defining more than one constructor in single class with different signature
d) Defining destructor with each constructor
27. Does constructor overloading include different return types for constructors to be overloaded?
a) Yes, if return types are different, signature becomes different.
b) Yes, because return types can differentiate two functions.
c) No, return type can’t differentiate two functions.
d) No, constructors don’t have any return type
28. Which among the following function can be used to call default constructor implicitly in java?
a) this()
b) that()
c) super()
d) sub()
30. Any changes made to static data member from one member function __________
a) Is reflected to only the corresponding object.
b) Is reflected to all the variables in a program.
c) Is reflected to all the objects of that class.
d) Is constant to that function only
31. Which is the correct syntax for declaring static data member?
a) static mamberName dataType;
b) dataType static memberName;
c) memberName static dataType;
d) static dataType memberName;
8|Page www.MoussaAcademy.com
00201007153601
32. The static data member ____________
a) Can be accessed directly.
b) Can be accessed with any public class name.
c) Can be accessed with dot operator.
d) Can be accessed using class name if not using static member function
33. Which of the following statement creates an object of Student class called MyStudent?
a) Student MyStudent = new Student():
b) Students Mystudent ()= new Student ();
c) Student = new MyStudent ();
d) MyStudent Student = new MyStudent ();
36. Which of the following creates an empty multidimensional array with dimensions 2×2?
a) int [] [] blue = new int[2, 2];
b) int [] [] blue = new int[2], [2];
c) int [] [] blue new int [2] [2];
d) int [] [] blue = new int[2 x 2];.
9|Page www.MoussaAcademy.com
00201007153601
38. ________ converts early assembly-language programs to machine language at computer speeds.
a) Editor
b) Compiler
c) Assembler
d) Executer
41. ___________ concept means one object acquires all the properties and behaviors of a parent object.
a) Modularity
b) Inheritance
c) Polymorphism
d) Encapsulation
10 | P a g e www.MoussaAcademy.com
00201007153601
43. A recursive method is terminated only if it has a ________.
a) for loop
b) base case
c) while loop
d) break statement
45. In inheritance, __________ keyword is used by the child class to access parent's variables, methods
and constructors.
a) super
b) extends
c) implements
d) protected
46. A class that represents the most general entity in an inheritance hierarchy is called a/an ________.
a) Superclass
b) Subclass
c) Inheritance class
d) Default class
47. What is the valid range of index values for an array of size 30?
a) 0 to 29
b) 1 to 30
c) 1 to 29
d) 0 to 30
11 | P a g e www.MoussaAcademy.com
00201007153601
48. Which of the following is incorrect about the constructor methods?
a) It has a return value.
b) It can take any number of parameters.
c) It can be used to initialize an object of a class when the object is created.
d) It has the same name as its class.
50. With reference to below java statement, choose the incorrect description of it.
final int FEE = 100;
a) It indicates that variable FEE is not modifiable.
b) You can change the variable's value but not the variable's name.
c) It declares variable FEE as a constant.
d) Any attempt to modify final variable results in error
51. Two methods having the same name with different number and types of parameters in a class are
known as __________.
a) method overloading
b) method overriding
c) method constructing
d) method duplicating
52. Which of the following is the correct way to define a static variable in Java?
a) private final int myNumber = 10;
b) private static int myNumber = 10;
c) private static int myNumber = "10";
d) private int myNumber = 10;
12 | P a g e www.MoussaAcademy.com
00201007153601
53. What is the output of the following java program?
class A{
private int x =100;
}
public class B{
public static void main(String[] args) {
A a= new A();
System.out.println(a.x);
}
}
a) There will be a run-time error.
b) There will be a compile-time error.
c) 100
d) a.x
13 | P a g e www.MoussaAcademy.com
00201007153601
57. What is the output of the following program?
class FinalTest {
int x =10;
FinalTest (int x) {
this.x = x;
}}
public class FinalTest2 {
public static void main(String args[]) {
FinalTest obj = new FinalTest (20);
System.out.print(obj.x); }
}
a) 20
b) There will be a compile-time error.
c) There will be no output.
d) 10
58. Variables declared inside the methods are always __________ variables.
a) void
b) global
c) public
d) local
59. In the String class, the _________ is used to compare the equality of two string values.
a) isEquals()
b) equals()
c) Equals()
d) IsEquals()
14 | P a g e www.MoussaAcademy.com
00201007153601
61. Which is the correct java code to print the following array declaration using enhanced for loop?
int[] arr = new int[4];.
a) for (int x: arr) System.out.print(x);
b) for (int arr: x) System.out.print(x);
c) for (String x: arr) System.out.print(x);
d) for (int x = arr) System.out.print(x);
64. You can get the values of private variables from outside its class by using ____________.
a) private get method
b) private set method
c) public set method
d) public get method
15 | P a g e www.MoussaAcademy.com
00201007153601
66. To create an object, you use a _______ keyword.
a) String[]
b) int[]
c) new
d) create
69. A variable that is declared inside a class but outside anything else such as a constructor or a method is
known as _________ variable.
a) private
b) public
c) local
d) instance
70. ________ variable is created at runtime and is shared among the agents at the class level.
a) local
b) private
c) public
d) static
71. The following code will print Welcome for _________ times.
for (int i = 1; i < 20; i = i*2) {
System.out.println("Welcome");}
a) Seven
b) Five
c) two
d) three
16 | P a g e www.MoussaAcademy.com
00201007153601
72. Consider the following java classes: Account and Main.
The account class is already defined for you.
Write the following code inside the main method in the main class.
• Create a new object of the account class.
• Use the set methods in the account class to set a new account ID, an amount of money, and You can
select any values you like.
Use the get methods to get all the values that you just created (i.e., account ID, amount of the money
and print them using the println() method.
Account.java
public class Account
private int accountID:
private int amount;
private String name;
// method that sets the account ID
public void setAccountID (int accountID) {
this.accountID = accountID; }
// method that sets the amount
public void setAmount (int amount) {
this.amount amount; }
// method that sets the name
public void setName (String name) {
this.name = name; }
public int getAccountID() {
return account ID; }
public int getAmount () {
return amount; }
public String getName () {
return name; }
}
Main.java
public class Main {
public static void main(String[] args) {
// write your code here.
// Create an object of the Account class
Account myAccount = new Account();
17 | P a g e www.MoussaAcademy.com
00201007153601
73. Write a Java statement (not a full program) to accomplish the following task:
1. Define a string variable named my_name that stores your first name.
2. Find and print the number of characters present in the string my_name using the length method in
the String class.
3. Replace your first name with your last name using the assignment operator and print the result.
// 1. Define a string variable named my_name that stores your first name.
String my_name = "YourFirstName";
// 2. Find and print the number of characters present in the string my_name using the length method
in the String class.
int numOfChars = my_name.length();
System.out.println("Number of characters: " + numOfChars);
// 3. Replace your first name with your last name using the assignment operator and print the result.
String lastName = "YourLastName";
my_name = lastName;
System.out.println("Updated name: " + my_name);
18 | P a g e www.MoussaAcademy.com
00201007153601
JAVA Final 2023
53 Questions
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
Java 1 Final Winter 2023
JAVA 1
Answers
Reviewed by:
Mamdouh Moussa
Moussa Academy
WWW.MOUSSAACADEMY.COM
Java 1 Final Winter 2023 ((الاجابات في نهاية المذكرة
A) superclass
B) parent class
C) base class
D) subclass
2. Which of the following methods is used to invoke the current class constructor
A) final ()
B) this()
C) enum()
D) catch()
3. The Java compiler ignores any text enclosed between and the end of the line.
A) ( )
B) ‘. ‘
C) //
D) " “
A) export
B) utilize
C) use
D) Import
C) HELLO WORLD!
D) Hello World!
1
6. In a Multi-Level Inheritance in Java, the last subclass inherits methods and properties of
A) The exam
9. Information can be passed to a method as parameters, which are specified after the function name,
inside the.....................and separated with a comma.
A) square brackets [ ]
B) braces { }
C) parentheses ( )
2
10. What is the output of the following Java code snippet?
int x = 0;
x = 50;
x = 100;
x += 45;
System.out.println(x);
A) 145
B) 50
C) 45
D) 100
11. In Java, a collection of related types (classes and interfaces) that provides namespace management
and access control
A) interface
B) lang
C) package
D) object
A) objects
B) classes
C) interfaces
D) access modifiers
13. is the action of a function that calls itself either directly or indirectly, where the associated me
known as method.
A) Lang, lang
B) Recursion, recursive
C) Translation, transitive
D) Interface, interface
14. In OOP, a/an................... is group of objects which have common properties. Moreover, it is a template
or blueprint of objects are created.
A) class
B) polymorphisme
C) abstract
D) interface
3
15. Which of the following Java code lines declares and initializes an integer array of size
16. The keyword indicates that the method should not return a value.
A) return
B) break
C) void
D) private
17. Which one of the following is the keyword that is used to implement an interface in Java?
A) implements
B) super
C) extends
D) Final
18. What is the valid range of index values for an array of size 20?
A) 0 to 20
B) 1 to 20
C) 0 to 19
D) 1 to 19
20. The constructor method has the ......... name as its class and has .......... return type.
A) different, double
B) same, no explicit
C) same, int
D) different, String
4
21. Which of the following is a correct statement used to create two new Java variables in one line?
22. R Questi Which of the following system software provides services that enable each program to
function concurrently (i.e., in parallel) with programs in a secure and efficient manner?
A) Distributed systems
C) Operating systems
D) Log file
23. Which of the following is the fundamental building block that must exist at least once in every Java
program
A) Class
B) Variable
C) CPU
D) Applet
24. A class can have references to one or more objects of other classes as members. This is called
A) overlapping
B) inheritance
C) overloading
D) composition
25. What is the output of the following Java code segment?if (1>3);
A) Know Program
B) Compilation Error
C) No output
D) 3
26. The is formed when a loop exists inside the body of another loop.
A) do/while loop
B) sentinel loop
C) nested loop
D) parallel loop
5
27. The predefined methods can be defined as methods that are
A) friends-defined methods
B) user-defined methods
C) internet-defined methods
28. What is the output of the following Java statement? System.out.println(Pattern.matches(".s", "as"));
A) false
B) as
C) True
D) s
A) break statement
B) base case
C) stop statement
30. The type is a special class that defines a set of constants represented as unique identifiers.
A) int
B) Char
C) enum
D) Boolean
32. programs allowed for the direct execution of high-level language programs without them to first be
translated into a machine language.
A) Abstraction
B) pointers
C) Exception
D) interpreter
6
33. What is the output of the following Java code snippet? char a = '6': system. Out. Println(
Character.isLetter(a)):
A) true
B) a
C) 6
D) false
34. The ........................ provides a default constructor that accepts no parameters when it is called if you
do not specify any in the declaration of a class.
A) compiler
B) recursion
C) composition
D) iteration
35. What is the output of the following Java code snippet? double x = 2; double y. = 3; double z = 1 - x
* Math. pow (x, 3) + (Math. pow (y, 2) + x) ; System.out.println (z);
A) -31.0
B) -4.0
C) 3
D) -37.0
36. Which of the following provides a code editor, a compiler or interpreter, and a debugger that the
developer can use through a graphical user interface?
37. Given the following array, which of the following lines inserts the value 10 in the last element of the
int [] arr= new int [15];
A) arr [10]=15;
B) arr [15]=10;
D) arr [14]=10;
7
38. What is the output of the following Java code segment?
int[] x = new int[3];
System.out.println("x[0] is " + x[1]);
A) x[0] is 3
B) x[0] is 0
C) Compilation Error
D) x[0] is 1
39. Which of the following is a keyword that acts as a non-access modifier for classes, and methods, in
unchangeable (not inheritable or overridable)?
A) assert
B) extends
C) final
D) default
A) 0
B) 2
C) 3
D) 1
A) objects
B) class variables
C) instance variables
42. Which one of the following is the keyword that is used to inherit a class?
A) implement
B) extends
C) extent
D) this
8
43. Which of the following is the correct word used in the statement of creating an object of the Car
class >
Car c = ____________Car ( )?
A) create
B) run
C) class
D) new
44. Which of the following is the correct string format for System. out .printf () to print an integer with a
width of 15?
A) "%15.0d"
B) "%15rd"
C) *%15d"
D) *%15r"
void ml(String x) {
System.out.print("One ");
}
}
}
A) Compilation Error
B) One Two
C) Two One
D) Runtime Error
9
46. What is the output of the following Java program?
A) 1
C) 2
int firstNo=45;
int secondNo=60;
firstNo=secondNo--;
System.out.println(firstNo + " & " + secondNo);
A) 60 & 59
B) 45 & 59
C) 45 & 60
D) 60 & 60
A) e l e m e n t
B) Compile error
C) j a v a
10
49. What is the output of the following Java program?
public class ABC {
private int num=100;
}
B) 100
D) obj.num
int arr[][]={{7,8,9},{4,5,6},{1,2,3}};
int sum=0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
sum=sum+arr[i][j];
}
}
System.out.println(sum);
A) 45
B) 11
C) 40
D) 10
11
51. What is the output of the following Java code snippet?
System.out.print(evenArr[0][0]);
System.out.print(evenArr[1][0]);
}
}
A) 410
B) 26
C) 28
D) 612
A) This
B) is
C) This is SEU
D) SEU
12
53. What is the output of the following Java program?
A) 2
B) 3
C) 0
D) No output
13
Answer Keys
1 D 28 C
2 B 29 B
3 C 30 C
4 D 31 C
5 B 32 D
6 D 33 D
7 A 34 A
8 D 35 B
9 A 36 D
10 A 37 D
11 C 38 D
12 D 39 C
13 B 40 B
14 A 41 A
15 B 42 B
16 C 43 D
17 A 44 C
18 C 45 B
19 B 46 A
20 B 47 A
21 C 48 C
22 C 49 A
23 A 50 A
24 D 51 C
25 C 52 D
26 C 53 B
27 D
14
JAVA Quiz Fall 2023
47 Questions
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
Java 1 – Solved Exam Quiz Fall 2023
Moussa Academy
00201007153601
WWW.MOUSSAACADEMY.COM
I. Multiple Choice Questions
1. If a method contains a local variable with the same name as an instance variable, the method's body
can use the keyword ____________ to refer to the shadowed instance variable explicitly.
a) public
b) shadow
c) private
d) this
b) False
c) 0
d) Null
a) Syntax Error
b) 9
c) 27
d) Runtime Error
1|Page www.MoussaAcademy.com
00201007153601
4. How many "int” values can be stored in a single element of an int type array?
a) 1
b) Unlimited
c) 10
d) 2
5. Which of the following method signatures is not considered an example of method overloading when
compared to the others?
a) static double add(double a double b)
b) static int add(int a, int b)
c) static double add1(int a, int b)
d) static int add(int a, int b, int c)
6. ________________ is defined as several methods of the same name, each with different parameters.
a) Method Overloading
b) Method Generalization
c) Method covering
d) Method Parameterization
a) 1 2 3 4 5
b) j j j j j
c) 0 1 2 3 4 5
d) 0 1 2 3 4
8. A/an _______________ would be used to have a loop that is inside another loop?
a) Nested loop
b) Nested if statement.
c) If statement
d) Method
2|Page www.MoussaAcademy.com
00201007153601
9. Consider the following Java code snippet:
int num1 = 10;
double num2 = 7.5;
int result = _____ num2 + num1;
What should replace the blank space to correctly compile and execute the code?
a) /
b) +
c) -
d) (int)
a) 5
b) 5.0
c) Error
d) Five
3|Page www.MoussaAcademy.com
00201007153601
12. What is the output of the following code?
a) 10
b) 5
c) 8
a) 15
13. Which of the following statements about the Java switch statement is true?
a) The "break" statement is required for every case in a switch statement
b) The switch statement can only be used with integer and character data types.
c) The "default” case in a switch statement is optional.
d) You can use a switch statement to compare complex data types, such as strings
14. If you want to create an if statement to verify if an integer variable myVar equals 40. Which condition
is correct?
a) if (myVar = = 40)
b) if ((myVarl 40) && (myVar !> 40))
c) if (myVar - 40 = 0).
d) if (myVar = 40)
4|Page www.MoussaAcademy.com
00201007153601
15. What is the output of the following code?
package abcpackage;
class Addition {
public int addTwoNumbers(int a, int b) {
return a + b;
}
}
package xyzpackage;
import abcpackage.*;
5|Page www.MoussaAcademy.com
00201007153601
19. What is the output of the following java code?
}
}
a) Excellent!
b) Well done.
c) Invalid grade
d) Great
20. Variables or methods declared with access modifier ____________ are accessible only to methods of
the class in which they're declared.
a) Public and private
b) Public
c) Public and default
d) Private
6|Page www.MoussaAcademy.com
00201007153601
22. In Java, what is the main purpose of a nested if statement?
a) To create loops.
b) To execute a block of code conditionally within another if statement.
c) To define custom data types.
d) To compare two variables
23. What is the default initial value for elements in an array of integers in Java?
a) 0
b) -1
c) null
d) 1
26. In Java, what does the "void" return type indicate for a method?
a) It returns a boolean value
b) It returns an integer
c) It does not return any value
d) It returns a String value
7|Page www.MoussaAcademy.com
00201007153601
27. What is the requirement regarding the data types of elements inside an array?
a) They must all be of the same type
b) They must be from related types
c) They must be from different types.
d) They must be only strings.
a) 6
b) 1
c) 4
d) 5
30. In Java, “int” in the method declaration, public int find Sum(), is called a/an ____________ .
a) Parameter
b) Return type
c) Access Modifier
d) Identifier
8|Page www.MoussaAcademy.com
00201007153601
33. What is the output of the following java code?
public class Example {
static int x = 8;
a) 8
a) 9
b) 10
c) 5
34. How should the condition be filled in the blank to make the following code print the integers from 5
through 15, inclusive?
a) j<=16
b) j<16
c) j<15
d) j==15
35. Which of the following loops ensures that its body is executed at least once?
a) for
b) do-while
c) for and while
d) while
9|Page www.MoussaAcademy.com
00201007153601
36. What type of loop in Java is best suited for situations where we know the repetition number?
a) do-while and while
b) while
c) do-while
d) for
39. When does the do-while loop test the loop continuation condition?
a) before or after executing the loop's body
b) before and after executing the loop's body
c) after executing the loop's body
d) before executing the loop's body
40. What term refers to the portion of a program that can reference an entity by its name?
a) Scope of instantiation
b) Scope of declaration
c) Scope of initialization
d) Scope of generalization
10 | P a g e www.MoussaAcademy.com
00201007153601
41. What is required to pass an array to a method in Java?
a) Declare a new array with the same name
b) The name of the array without brackets
c) The array cannot be passed from another method
d) The name of the array with brackets
42. In Java, “int a” in the method declaration, public void print(int a), is called a/an___________.
a) Identifier
b) Access modifier
c) Parameter
d) Return type
a) FALSE
b) TRUE.
c) TRUE: FALSE
d) Runtime error
44. The ______ package contains classes and interfaces for enabling data input and output.
a) Java.io
b) Javax.swing
c) Java.util
d) Java.lang
45. _______________ is/are defined as Classes grouped into categories of related classes.
a) Java programs
b) Applications
c) Packages
d) Overloading
11 | P a g e www.MoussaAcademy.com
00201007153601
46. What is the output of the following java code?
package abcpackage;
class Addition {
private int addTwoNumbers(int a, int b) {
return a + b;
}
}
package xyzpackage;
import abcpackage.*;
a) Syntax Error
b) Compile time Error
c) 6
d) 7
a) 8
b) 5
c) 10
d) 9
12 | P a g e www.MoussaAcademy.com
00201007153601