Java_Fundamental_exam type
Java_Fundamental_exam type
1 mark
1. The default value of a static integer variable of a class in Java is
A. 0
B. 1
C. -1
D. Null
E. 0.0
2. Among these expressions, which is(are) of type String? 1 mark
A. “KoKo123”
B. “0123” + “23”
C. 50 + 100
D. “true”
E. ‘J’
3. Syntax that creating an array for is 1 mark
A. char oop [] = new oop[5]
B. char [] oop = new opp[5]
C. char oop [] = new char [5]
D. char [] oop = new char[5]
E. char [] oop = new char oop[5]
4. How many arithmetic operators are there? 1 mark
A. 7
B. 6
C. 5
D. 4
E. 3
5. How many primitive datatypes are there in Java? 1 mark
A. 4
B. 1
C. 8
D. 10
E. 6
1|Page
1 mark
6. Which of the following is not a valid Java identifier?
A. _myVar
B. $myVar
C. 2myVar
D. myVar2
E. #myVar
7. Which of the following is a valid declaration of a main method in a Java class? 1 mark
2|Page
11. In Java, what is the purpose of the ‘break’ statement? 1 mark
A. if-else
B. for-each
C. do-while
D. try-catch-finally
E. try-catch
14. What is the default value of a boolean variable in Java? 1 mark
A. true
B. false
C. null
D. 1
E. 0
15. What is the keyword used to define a constant variable in Java? 1 mark
A. static
B. global
C. final
D. const
E. constant
3|Page
1 mark
16. Which of the following is true?
A. A finally block is executed before the catch block but after the try block.
B. A finally block is executed, only after the catch block is executed.
C. A finally block is executed whether an exception is thrown or not.
D. A finally block is executed, only if an exception occurs.
E. None of the above.
A. false
B. true boolean result = (10 + 5) > 10 && 0 <= (5 - 5);
C. 0 System.out.println(result);
D. Error
E. Null
19. Which of the following data types is not a primitive data type in Java? 1 mark
A. int
B. float
C. boolean
D. String
E. char
20. What is the default value for an element in an integer array in Java? 1 mark
A. 0
B. -1
C. 1
D. Null
E. 0.0
4|Page
21. What is the result of System.out.println ("9" + 3 + "AB" + "2*3" + 2);
2 marks
___________________________________________
22. What is the answer of 5 * 3 + 12 / 4 - 2 according to Java internal rule of precedence? 2 marks
___________________________________________
2 marks
23. How to declare and initialize two-dimensional array in Java?
___________________________________________
2 marks
24. What will be the output of the following code?
int a = 5;
int b = 3;
int c = a++ * b--;
System.out.println(c);
____________________________________________
int x = 7;
int y = 3;
int result = x / y + x % y;
_____________________________________________
26. What is the answer of (5+1) - 5 * 7 + 9 / 7 - 2 +(-3 * 2) according to Java internal rule of
precedence? 2 marks
_____________________________________________
5|Page
28. If d is 37, what is the value of c after the code is executed? 2 marks
int c = 12;
while (c <= d + 100) {
c = c + d;
}
_______________________________________________
int H = 9 , M = 5 , I = 0;
while (I <= H--) {
M += I ;
I++;
}
_______________________________________________
30. Write the statement that must the loop to go through Q from 0 to 20(included) and increment
is three? 2 marks
_______________________________________________
System.out.println(numbers[i]);
__________________________________________________
32. What is the output of numbers array after the code is executed? 2 marks
int[] numbers = new int[12];
numbers[i] = i * i;
__________________________________________________
6|Page
33. What is the value of p after the code is executed? 2 marks
int p = 2;
for (int k = 0; k <=8; k++) {
p+=2;
}
_______________________________________________
System.out.println("Legendary");
}
if(value != 10 || value == 12) {
System.out.println("Champion");
}
else {
System.out.println("Epic");
_______________________________________________
________________________________________________
7|Page
36. What is the value of ‘index’ after the code is executed? 2 marks
_______________________________________________
___________________________________________________
__________________________________________________
8|Page
39. What is the output of the following code? 2 marks
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
cars[0] = "Opel";
System.out.println(cars[0]);
System.out.println(cars.length);
__________________________________________________
____________________________________________________
___________________________________________________
9|Page
42. A farmer is asking you to tell him how many legs can be counted among all his animals. The
farmer breads four species chickens, cows, ducks and pigs. What is the value of total number
of legs of all the animals and total of animals in the following code. 4 marks
public static void Legs(int a , int b , int c , int d) {
a = a * 2;
b = b * 4;
c = c * 2;
d = d * 4;
System.out.println("Total Legs = " + (a + b + c + d));
}
public static void main(String args[]) {
int chickens = 4, cows = 5, ducks = 6, pigs = 4;
Animals(chickens , cows , ducks , pigs);
Legs(chickens , cows , ducks , pigs);
}
public static void Animals(int a , int b , int c , int d) {
System.out.println("Chickens = " + a);
System.out.println("Cows = " + b);
System.out.println("Ducks = " + c);
System.out.println("Pigs = " + d);
}
___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
10 | P a g e
43. It’s Birthday Party, could be your party. Look the cake how it is big and delicious. The cake
could split 15 slices. You are going to determines how that slices of cake are possible or
impossible to share your family members and friends FAIRLY if they’re 7 in the following
code. Possible or Impossible? 4 marks
______________________________________________________
______________________________________________________
44. Write a Java program that output the following result of two-dimensional arrays. 4 marks
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
______________________________________________________
______________________________________________________
______________________________________________________
______________________________________________________
______________________________________________________
______________________________________________________
11 | P a g e
45. Write a program that output the following result multiply of 12. 4 marks
12 * 1 = 12
12 * 2 = 24
12 * 3 = 36
12 * 4 = 48
12 * 5 = 60
12 * 6 = 72
12 * 7 = 84
12 * 8 = 96
12 * 9 = 108
12 * 10 = 120
12 * 11 = 132
12 * 12 = 144
________________________________________________________
________________________________________________________
________________________________________________________
________________________________________________________
________________________________________________________
1 2 3 4 5
1 2 3 4
1 2 3
1 2
________________________________________________________
________________________________________________________
________________________________________________________
________________________________________________________
12 | P a g e
47. What is the output of the following nested loop? 8 marks
13 | P a g e
48. What is the output of the following nested loop? 8 marks
14 | P a g e
Aung Phyo Paing (Thompson LanKee)