ype of game Types of questions which appear
Deductive Logical
Finding the missing symbol/ visual in a grid based on a rule-based logic
Thinking
Inductive Logical Visual Based Questions of the type where you are expected to find which pair of fig
Thinking the question
Ability to focus your attention is measured.
Grid Challenge Question types are:
1. Symmetry check between two different grids
2. Recalling sequence of tasks
Ability to plan ahead is measured.
Motion Challenge
Has puzzles where you must find the path between two points in a maze - in the leas
many puzzles as you want.
Apti
English Comprehension
Passage
Elimination Round Algorithm Sudoku available in you tube
Capgemini Game Based Aptitude Test: Questions and
Answers
Here are some questions and answers that will help you
understand how theCapgemini Game Based Aptitude Test
works.
Q1. Which operator is needed?
Answer: 2341
Explanation:
From the given row,
Position 1 is occupied by a circle
Position 2 is occupied by a plus sign
Position 3 is occupied by a rhombus
Position 4 is occupied by a triangle
After 2413,
Position 1 is occupied by a Plus sign
Position 2 is occupied by a Triangle
Position 3 is occupied by a Circle
Position 4 is occupied by a Rhombus
In the final row, the order is a triangle, circle, rhombus,
plus sign which can be translated as 2341.
Q2. Pick the one that doesn’t fit the group.
Answer: E
Explanation:
In each step, the shaded square moves 1 position in an
anticlockwise direction along the sides of the outer square. In
figure E, the shaded square should be along the top edge of
the outer square. But it was given along the bottom edge of
the outer square and hence the odd man.
Q3. Find the missing part.
Answer:
Explanation:
Each row/ column should have all five shapes (triangle, plus
sign, square, circle, star).
If we consider row 2, a star can be fixed only at grid 23. So, a
plus sign can be fixed at the first column of the second row.
So, the question should be replaced by a plus sign.
Q4. Enter the unique digits that satisfy the given equation.
Answer: 6 × 7 + 3 = 45
Q5.
Answer:
Explanation:
Elements along the diagonal are similar.
Q6. Identify the pattern in which the question grids are
coloured and following the same pattern colour the given
grids.
Answer:
Explanation:
Grids with elements in the range of 0 to 4 are coloured green.
Grids with elements in the range of 5 to 9 are coloured grey.
Q7. Pick the odd one.
Answer: B
Explanation:
A vertical line, a plus sign and a cross mark repeat in a cycle.
Q8. Move the red ball to the hole (marked black) in the given
grid.
Answer & Explanation:
The required moves are:
i) Purple block and the ball – 2 positions leftward
ii) Green block – 2 positions upward
ii) Brown block – 1 position rightward and 1 position upward
iii) Yellow block – 1 position downward and 1 position
rightward
After these movements, the grid changes as:
Now, the red ball can be taken to the destination without
obstacles.
Q9. Find the missing part.
Answer: C
Explanation:
Considering column wise,
Figure 1 + Figure 2 = Figure 3
The non-overlapping parts between figures 1 and 2 are
shaded in yellow. The overlapping parts are shaded in blue.
Q10. Enter the unique digits that satisfy the given equation.
Answer:
3÷6×4=2
1÷3×6=2
1÷4×8=2
3÷9×6=2
Q11. Identify the order of rearrangement.
Answer: 3241
Explanation:
From the given row,
Position 1 is occupied by a square
Position 2 is occupied by a triangle
Position 3 is occupied by a plus sign
Position 4 is occupied by a circle
In the final row, the order is a plus sign, triangle, circle, a
square which can be translated as 3241.
Q12. Pick the one that doesn’t fit the group.
Answer: (Vth figure)
Explanation:
In the given series of IX figures (say I to IX), each figure
contains 5 horizontal lines (say 1 to 5). Exactly one of the
lines is broken in the order of 1, 2, 3, 4, 5, 4, 3,2, 1 from
figures I to IX respectively. But this order is missed in the
Vth figure. Hence is the odd man.
Q13. Pick the one that doesn’t fit the group.
Answer: IIIrd figure
Explanation:
In each of the given IX figures, there are two shapes, out of
which, one is shaded and the other is unshaded. But only in
the third figure, the two shapes overlap each other. Hence is
the odd man.
Q14. Find the missing part.
Answer:
Explanation:
Each row/ column should have all four shapes (triangle, plus
sign, square, circle).
If we consider column 4, grid 14 should be occupied by a
circle. So, grid 13 will be occupied by a plus sign.
Q15. Enter the unique digits that satisfy the given equation.
Answer: 3 × 4 + 8 = 20
Q16.
Answer:
Explanation:
The rule followed by grids given in the question: Row 1 and
Row 3 are identical.
Q17. Identify the pattern in which the question grids are
coloured and following the same pattern colour the given
grids.
Answer:
Explanation:
The grids with 4 ‘Z’s are coloured yellow and the remaining
grids are coloured black.
Q18.
Answer: 3241
Explanation:
From the given row,
Position 1 is occupied by a plus sign
Position 2 is occupied by a circle
Position 3 is occupied by a triangle
Position 4 is occupied by a rhombus
After the operator 4312 the order changes as Rhombus,
Triangle, Plus sign, Circle
From this order to get the given final order of Plus sign,
Triangle, Circle, Rhombus, the required operator is 3241.
Q19. Move the red ball to the hole (marked black) in the
given grid.
Answer & Explanation:
The required moves are:
i) Blue block – 1 position upward
ii) Purple block – 1 position leftward and 1 position upward
iii) Green block – 1 position upward and 1 position leftward
After these movements, the grid changes as:
Now, the red ball can be taken to the destination without
obstacles.
Q20. Enter the unique digits that satisfy the given equation.
Answer: 3 × 8 + 6 = 30
Q21. Remember the order in which the dots appear on a
grid. In between the grids, some questions are to be
answered whether the given pictures are symmetrical or not.
At last, the dots are to be marked as per the order.
Q22. Pick the one that doesn’t fit the group.
Answer:
Explanation:
From the right end, the number of plus signs inside a box
increases by 1 in each consecutive figures. But the order is
missed at the fifth figure and hence is the odd one.
Q23. Identify the pattern in which the question grids are
coloured and following the same pattern colour the given
grids.
Answer:
Explanation:
The grids with only numbers are marked grey while the grids
with both numbers and alphabets are marked green.
Q24. Find the missing part.
Answer:
Explanation:
To find the part to be filled on grid 12, let us first consider
other grids related to it.
Grid 51 – Square;
Grid 21 – Triangle;
Grid 11 – Circle;
Grid 45 – Triangle;
Grid 15 – Star;
So, grid 12 will be occupied by a triangle.
(As a triangle can’t be fitted on grid 13 or 14)
Q25. Find the missing part.
Answer:
Explanation:
Each row and column should have exactly one cross mark. As
the pattern already exists on the question figure, the missing
part should not contain any cross marks.
What will be the output of the following pseudocode?
Integer i
Set i = 3do
print i + 3
i = i - 1while(i not equals 0)
end while
[Note: A do-while loop is a control flow statement that
executes a block of code at least once, and then repeatedly
executes the given Boolean condition at the end of the block]
A) 6 6 6
B) 6 5 6
C) 5 5 5
D) 6 5 4
Ans: D
Explanation:
In this program, one variable declared as i, and the value
initialized as 3. We are moving with do-while(Do while will
execute the statement once and then it will check the
condition).
Step 1:
It will print i+3, here i value is 3. So i+3 is 6. On the next line,
i will be decremented by 1. Then checking the conditions in
do-while() i!=0. Here updated i value is 2 (2!=0),so condition
is true. The loop continues.
Step 2:
It will print i+3, here the updated i value is 2. So i+3 is 5. On
the next line, i will be decremented by 1. Then checking the
conditions in do-while() i!=0. Here updated i value is 1 (1!
=0),so condition gets true. The loop continues
Step 3:
It will print i+3, here the updated i value is 1. So i+3 is 4. On
the next line, i will be decremented by 1. Then check the
condition in do-while() i!=0. Here updated i value is 0 (0!
=0),so condition gets false. Thus the loop gets terminated!
E.g. code to explain this:
Do while will execute the statement for the first time and
then it will check the condition.
int i=3;
do{
cout<<i+3; => 3+3 =6 =>2+3 =>5 =>1+3=4
i=i-1; => 3-1=2 =>2-1 =>1 =>1-1=0
}while(i!=0);
Q2. What would be the output of the following pseudocode?
Integer a
String str1
Set str1 = “goose”
a = stringLength(str1)
Print (a ^ 1)
[Note- string-length(): string-length() function counts the
number of characters in a given string and return the integer
value.
^ is the bitwise exclusive OR operator that compares each bit
of its first operand to the corresponding bit of its equal
operand. If one bit is 0 and the other bit is 1, the
corresponding result bit is set to 1. Otherwise, the
corresponding result bit is set to 0]
A) 0
B) 4
C) 5
D) 3
Ans: B
Explanation:
There are two variables a and str1. Value initialized for str1
is “goose”. On the next line, we are finding the length of str1
that is 5. Finally, printing the output of a bitwise exclusive OR
operator with 1. And the answer is 4.
E.g. code to explain this:
{
int a;
string str1="goose";
a = [Link](); => length of String is 5
cout<<(a^1); 5 xor 1 => 4
}
Q3. What would be the output of the following pseudocode?
Integer a, b, c
Set a = 8, b = 51, c = 2
c = (a ^ c)^ (a)
b = b mod 4
Print a + b + c
[Note- mod finds the remainder after the division of one
number by another. For example, the expression “5 mod 2”
would evaluate to 1 because 5 divided by 2 leaves a quotient
of 2 and a remainder of 1
^ is the bitwise exclusive OR operator that compares each bit
of its first operand to the corresponding bit of its equal
operand. If one bit is 0 and the other bit is 1, the
corresponding result bit is set to 1. Otherwise, the
corresponding result bit is set to 0]
A. 13
B. 17
C. 26
D. 16
Ans: A
Explanation:
There are three variables a, b and c declared. Value
initialized for a is 8, b is 51 and c is 2.
When we do a bitwise exclusive OR of (8^2), the answer is
10. Again 10 bitwise exclusive OR of a i.e (10 ^ 8) is 2, which
will be stored in variable c.
Then taking modulo operation for b by 4 (b%4) the answer is
3
Finally adding all the updated values of a,b, and c (8+2+3 )
and the output of Pseudocode is 13.
E.g. code to explain this:
int main()
{
int a=8,b=51,c=2;
c = (a ^ c)^ (a); =>(8^2) ^(8) => 10 ^ 8 => 2
b = b % 4; =>3
cout<<a + b + c; =>8+2+3 => 13
}
Note: ^ is the bitwise exclusive OR
Q4. Consider an array A = {1, 2, 4, 5, 6, 11, 12} and a key
which is equal to 10. How many comparisons would be done
to find the key element in the array using the binary search?
A) 5
B) 1
C) 2
D) 3
Ans: D
Explanation:
There is an Integer Array A = {1, 2, 4, 5, 6, 11, 12} and the
key value is 10.
Binary search applies only to the sorted ordered list.
We know that binary search takes log n base 2 times to
search for a particular element.
If there are N elements in the set you have chosen binary
search then take log n base 2 times.
1. First, you check how many elements in your array. if an element in your
array is greater than 1 then you go for the next step.
2. Binary search divides the problem into two parts using the mean of the
total number of an element which is sorted mean=(0+n)/2
3. And compare the searching element which is either greater than the
mean or lesser or equal to the mean .then after comparison skips the
one part either greater part or small part depends on the result of
searching is done if the mean is equal to the searching element. So that
problem is divide into n/2 and goes until searching is done.
If you apply the recursive equation for the binary search
algorithm then
T(n)=T(n/2)+1 to solve the problem
n/2^k=1
taking log on both sides
log n=log (2^k)
log n= k log 2
k=log n base 2.
N=7
K=log 7 base 2 = 3
K=3
So, the answer becomes 3.
Q5. What would be the output of the following pseudocode?
Integer i, j, k
Set k = 8for(each i from 1 to 1)
for(each j from the value of i to 1)
print k+1
end for
end for
A. 2
B. 9
C. 7
D. 8
Ans: B
Explanation:
There are three variables i, j, and k declared. Value initialized
for k is 8, In this code, we are moving with nested for loop.
Here I value is 1, for loop will check the condition i<=1
condition gets true. Now, moving with inner for loop j value
will be 1 condition gets true j<=[Link], it prints K+1. Then j
value will be incremented by 1(2<+1) inner for loop condition
gets false.
On the next iteration, i value will be incremented by 1, here
the updated i value is 2 (2<=1) condition get false. So the
answer is 9.
E.g. code to explain this:
int i, j, k;
k = 8;
for(i=1 ;i<=1;i++){ => i=1 True
for(j=i;j<=1;j++){ => j=1 true
cout<< k+1; => print k+1 => 8+1 =>9
}
}
[Link] will be the output of the following pseudocode?
Integer a, b
Set a = 15, b = 7
a = a mod (a - 3)
b = b mod (b – 3)
a = a mod 1
b = b mod 1
Print a + b
A) 15
B) 7
C) 2
D) 0
[Note-mod finds the remainder after the division of one
number by another. For example, the expression “5 mod 2”
leaves a quotient of 2 and a remainder of 1]
Answer: 0
Explanation:
There are two variables a and b declared. Value initialized for
a is 15 and b is 7. Taking mod operation for a by 12(a%12)
and the answer is 3 will stored in a.
The next mod operation for b is 7 mod (7%4). The answer is 3
will be stored in b.
The next line takes the updated value of a and mods it by
1(3%1). Then the answer becomes 0 will be stored in a.
The next line takes the updated value of b mod by 1 (3%1)
then the answer is 0. Finally adding all the updated values of
a and b (0+0 ) and the output of Pseudocode is 0.
Q7. What will be the output of the following pseudocode?
Integer a, b, c
Set b = 5, a = 2, c = 2if(b>a && a>c && c>b)
b=a+1
Else
a=b+1
End if
Print a + b + c
[Note-&&: Logical AND - The logical AND operator (&&)
returns the Boolean value true(or 1) if both operands--. If (x)
gets executed if the value if(), i.e., x is not zero]
A) 2
B) 13
C) 26
D) 5
Ans: B
Explanation:
There are three variables a, b and c declared. Value
initialized for a is 2, b is 5 and c is 2.
Checking the condition using if, b >a and a>c and c>b here if
conditions get false. Now else part will execute b value will be
incremented by 1 and stored in a, Finally adding all the
updated values of a, b and c (6+5+2 ) and the output of
Pseudocode is 13.
Q8. For which of the following applications can you use
hashing?
1. To construct a message authentication code.
2. For Timestamping
3. For detecting a cycle in a graph
Choose the correct answer from the options given below.
A) Only 1 and 3
B) Only 2 and 3
C) Only 1
D) Only 1 and 2
Ans: D
Explanation:
Constructing a message authentication code and
Timestamping are the real-time applications for hashing.
Q9. Consider an array of float. Calculate the difference
between the address of the 1st and 4th element, assuming
float occupies 4 bytes of memory.
A) 16
B) 4
C) 12
D) 8
Ans: C
Explanation:
Let's consider the address of elements:
1st element – 1000 - 1003 (4 bytes)
2nd element – 1004 - 1007 (4 bytes)
3rd element – 1008 – 1011 (4 bytes)
4th element - 1012 – 1015 (4 bytes)
The difference between the address of the 1st and 4th
elements is 12.
Q10. What is the second part of a node in a linked list that
contains the address of the next node called?
A. data
B. pointer
C. element
D. Link
Ans: D
Explanation:
The field of each node that contains the address of the next
node is usually called the 'link'.
Q11. If you are using a Depth-first search (DFS) for
traversing an unweighted graph, then which of the following
will happen?
1. It produces the minimum spanning tree
2. It produces all pair shortest path tree
Choose the correct answer from the options given below.
A) Both 1 and 2 are true
B) Both 1 and 2 are false
C) Only 2 is true
D) Only 1 is true
Ans: D
Explanation:
Depth-first search (DFS) for traversing an unweighted
graph, will produce the minimum spanning tree.
Only Depth-first search (DFS) for traversing a weighted
graph, will produce all pair shortest-path tree.
Q12. With the given information provided find out the
address of Arr[17] in a 1-D array Arr[30].
- lower bound = 1
- starting base address = 1100
- size of each element is 2.
A) 1132
B) 1070
C) 1128
D) 1068
Ans: A
Explanation:
We need to find the address of Arr[17]. Starting base address
is 1100.
Arr[1] – 1100 (2bytes)
Arr[2] – 1102 (2bytes)
Arr[3] – 1104 (2bytes)
Arr[4] – 1106 (2bytes)
Arr[5] – 1108 (2bytes)
Arr[6] – 1110 (2bytes)
Arr[7] – 1112 (2bytes)
Arr[8] – 1114 (2bytes)
Arr[9] – 1116 (2bytes)
Arr[10] – 1118 (2bytes)
Arr[11] – 1120 (2bytes)
Arr[12] – 1122 (2bytes)
Arr[13] – 1124 (2bytes)
Arr[14] – 1126 (2bytes)
Arr[15] – 1128 (2bytes)
Arr[16] – 1130 (2bytes)
Arr[17] – 1132 (2bytes)
Thus, the Answer for arr[17] is 1132
Q13. What will be the output of the following pseudocode?
Integer arr[]={10, 20, 30, 40, 5}
Integer a, s
Set s = 0Set a = arr[1] + arr[2]
Print a
A) 25
B) 5
C) 50
D) 40
Ans: C
Explanation:
There is an array of integer arr[]={10,20,30,40,50}. There
are two variables a and b declared. . The value initialized for
s is 0. On the next line adding the 1st index value 20 and 2nd
index value 30 arr[1] + arr[2]( 20+30), the answer is 50 will
be stored in a. Finally printing the updated values of a is 50.
Q14. What will be the output of the following pseudocode?
Integer a, b, c
Set b = 2, a = 2
c=a^b
Print c
[Note- ^ is the bitwise exclusive OR operator that compares
each bit of its first operand to the corresponding bit of its--
other bit is 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0]
A) 6
B) 4
C) 0
D) 2
Ans: C
Explanation:
There are three variables a, b and c declared. Value
initialized for a is 2 and b is 2. When we do a bitwise
exclusive OR of c i.e (2^2), the answer is 0. Finally, print the
value of c.
Q15. Which of the following series will be printed by the
given pseudocode?
Integer i, j, k, n
Set j=1, k=1for(each i from 1 to 5)
print k
j=j+1
k=k+j
end for
A) 1 3 6 10 15
B) 1 2 3 4 5
C) 2 4 6 8 10
D) 1 1 2 3 5
Ans: A
Explanation:
There are four variables i, j,k, and n declared. Value initialized
for j is 1 and k is 1.
For loop, i value starts from 1 loop will run till the i<5, In the
first iteration i value, is 1, printing k value is 1. Next line j
value will be incremented by 1 (1+1) =>2. On the next line
adding k and j (1+2), then the answer is 3.
2nd iteration i value will be incremented by 1, i=2. Print k,
the updated k value is 3. on the next line j value will be
incremented by 1 (2+1) =>3. On the next line adding k and j
(3+3) , then the answer is 6.
3rd iteration i value will be incremented by 1, i=3. Print k, the
updated k value is 6. on the next line j value will be
incremented by 1 (3+1) =>4. On the next line adding k and j
(6+4) , then the answer is 10.
4th iteration i value will be incremented by 1, i=4. Print k, the
updated k value is 10. on the next line j value will be
incremented by 1 (4+1) =>5. On the next line adding k and j
(10+5) , then the answer is 15.
5th iteration i value will be incremented by 1, i=5. Print k, the
updated k value is 15. Next line j value will be incremented
by 1 (5+1) =>6. On the next line adding k and j (15+6), then
the answer is 21.
Here for loop condition gets false, it comes out of
the for loop. The output of Pseudocode is 1 3 6 10 15.
Capgemini Pseudocode Questions and
Answers (Previously Asked)
Question 1:
Find the output of the following pseudo-code:
Integer x,y,z;
x=0
y=1
x=y=z=8
Print x
Options:
A) 0
B) 8
C) 1
D) None of the above
Correct Answer: Option B
Explanation: In this question, the value of x is initialized as
0 and y as 1 in the beginning. Later the value 8 is assigned to
the variable z and the value of z is assigned to the variable y
and the value of y is assigned to the variable x. Finally, the
value of x is updated as 8.
Question 2:
Find the output of the following pseudo-code:
Integer value, n
Set value = 1, n = 45while(value less than equal to n)
value = value << 1
end loop
Print value
Options:
A) 64
B) 32
C) 45
D) None of the above
Correct Answer: Option A
Explanation: Here, the left shift operation pushes the
values towards the left once; when 1 is left-shifted the value
that we will be obtaining will always be 2 to the power
something. When one is converted in the beginning and not
shifted the value will be 2^0 which is 1. The next iteration
will be pushed one place towards the left, therefore the value
now will be 2^1 which is 2; this will go on happening until the
value stored is greater than 45. The value which is greater
than 45 in 2 powers is 64. Now the loop terminates and the
last value stored in the variable is 64 and the same will be
printed.
Question 3:
Find the output of the following pseudo-code:
Integer c, d
Set c = 15, d = 12
d=c–1
Print c //line
c = d + (c – 2)
if(c < 40)
Goto line
end if
Options:
A) 14 26 38
B) 27 39
C) 15 27 39
D) None of the above
Correct Answer: Option C
Explanation: c and a is initialized, and d as well; line 5 we
are re-initializing c in every iteration of goto; the goto loop
terminates only when the value of c is greater than 40 the
last value stored in c which breaks the if the condition is 51
and all the numbers 15 27 and 39 will be printed according to
the algebraic expression in line number 5.
Question 4:
Find the output of the following pseudo-code if x= 4 and y=5:
Integer fun(int x, int y)
if(x > 1)
fun(x – 2, y + 2)
end if
print y
End function fun()
Options:
A) 4 5 6
B) 7 6 5
C) 9 7 5
D) None of the above
Correct Answer: Option C
Explanation: the first reverse recursion would print 9 and
returns to a previous function call, next it prints 7 and returns
to the very first function call finally it prints a 5 and
completes the execution.
Question 5:
How many times will the print statement be executed:
Integer a, b, c
Set a = 8, b = 10, c = 6
If(a > c AND (b + c) > a)
Print a
end ifif(c > b OR (a + c) > b)
Print b
end ifif((b+c) MOD a EQUALS 0)
Print c
end if
Options:
A) 2
B) 3
C) 1
D) 0
Correct Answer: Option B
Explanation: All the conditions are true when checked with
the condition so the print statement will be executed 3 times.
Question 6:
What will be the output if the following pseudocode if a=10
and b=6:
Integer func (Integer a, Integer b)
Integer temp
while(b)
temp = a MOD b
a=b
b = temp
end whilereturn a
End function func()
Options:
A) 2
B) 4
C) 3
D) 1
Correct Answer: Option A
Explanation: The while loop will only terminate when the
value of b becomes zero, this will happen only after the 4th
iteration when the last value of the b will be zero and the
value of a is 2
Question 7:
What will be the output of the following pseudo-code?
Integer x, y, z
Set x=24, y=8
x = x/y
z = y<<x
Print z
[Note: << is left shift operator, it takes two numbers, left
shifts the bits of the first operand, the second operand
decodes the number of …]
Options:
A) 1
B) 8
C) 0
D) 64
Correct Answer: Option D
Explanation: When the x is reinitialized in line 3 the value
stored will be 3. Therefore 8 has to be left-shifted thrice. The
shifted value is the 3rd next power of 2 that is 2^6 and the
value is 64.
Question 8:
What will be the output of the following pseudocode?
Integer x, y, z, a
Set x = 2, y = 1, z = 5
a = (x AND y) OR (z + 1)
Print a
Options:
A) 5
B) 3
C) 2
D) 1
Correct Answer: Option D
Explanation: AND gate works when both the conditions are
true so the first (x and y) condition will be taken as true as
both the inputs are true. OR gate works when any of the
conditions are true, where it has already got one of its input
as true so without checking the other input it will directly
assign the value as 1.
Question 09:
What will be the output of the following pseudocode?
Integer a=5, b=4, c=3
a=b+c
c=a–b
c=c+a
c=b+c
b=b+c
Print a, b, c
Options:
A) 7 14 7
B) 7 14 10
C) 7 8 14
D) 7 18 14
Correct answer: Option D
Explanation: The intial values of a=5, b=4, c=3
a = 4 +3 = 7
c=7–4=3
c = 3 + 7 = 10
c = 4 + 10 = 14
b = 4 + 14 = 18
Print 7, 18, 14
Question 10:
What will be the output of the following pseudocode?
Integer a, b, c, d
Set b = 18, c = 12
a=b–c
for (each c from 1 to a – 1)
b = b + c + 12
b = b/5
d=b+a
end for
c=a+b+c
Print a b c
Options:
A) 5 3 9
B) 6 14 17
C) 6 4 14
D) 6 4 16
Correct Answer: Option D
Explanation: The loop runs for 5 times; after the 5th
iteration the value of a=6; b=4; c=10.
So the final answers are 6, 4, 16
Question 11:
Which of the following operations is possible on an array?
Options:
A) All of the mentioned options
B) Insertion
C) Searching
D) Sorting
Correct Answer: Option A
Explanation: It is trickier when it comes to arrays to do the
operation in comparison with the linked lists. But they are
definitely possible
Question 12:
An abstract data type is defined to be a mathematical model
of a user-defined type along with the collection of all ________
operations on that model.
Options:
A) Union
B) Assignment
C) Primitive
D) None of the above
Correct Answer: Option A
Explanation: In computer science, an abstract data type
(ADT) is a mathematical model for data types. An abstract
data type is defined by its behaviour (semantics) from the
point of view of a user, of the data, specifically in terms of
possible values, possible operations on data of this type, and
the behaviour of these operations. These are not possible in
union and assignment operations.
Question 13:
What do we call the binary tree nodes with no successor?
Options:
A) End nodes
B) Terminal nodes
C) Last nodes
D) Final nodes
Correct Answer: Option B
Explanation: The official terminology is Terminal node or
leaf node;
Question 14:
What do we call the highest element of an array’s index?
A) Upper bound
B) Lower bound
C) Range
D) Extraction
Correct Answer: Option A
Explanation: The upper bound is always the highest
element of an array index.
Question 15:
Which of the following data types represents many to many
relations?
A) Both plex and graph
B) Graph
C) Plex
D) Tree
Correct Answer: Option A
Explanation: A many-to-many relationship occurs when
multiple records in a table are associated with multiple
records in another table. This is possible only with the help of
Both plex and graph.
Question 16:
Which of the following is NOT a type of linked list?
A) Double ended linked list
B) Double linked list
C) Simple linked list
D) Circular linked list
Correct Answer: Option A
Explanation: We just have 3 types of linked list among the
given options b, c, and d. A double-ended linked list does not
exist.
Question 17:
Each node of the graph is represented as a _______?
A) Vertex
B) Root
C) Path
D) Edge
Correct Answer: Option A
Explanation: Every node cannot be a root node and path,
the edge is related to the directions of the graph.
Question 18:
Recursion uses more memory space than iteration. Which of
the following is/are the valid reason for the same?
A. It uses the stack instead of a queue
B. Every recursion call has to be stored
Choose the correct answer from the options given below.
A) Only A
B) Both A and B
C) Neither A nor B
D) Only B
Correct Answer: Option A
Explanation: Recursive functions use the stack as the
memory space technique. And also as rightly pointed out the
call has to be present to store the returned values.
Question 19:
To which of the following domain problem does the knapsack
problem belong?
A) NP-complete
B) Sorting
C) Optimisation
D) Linear Solution
Correct Answer: Option C
Explanation: knapsack algorithm is used to find the
maximum profit out of the least weight combination possible,
therefore it definitely belongs to an optimization domain.
This round is divided into two parts. They are:
Technical Interview
HR Interview
Capgemini Interview Questions - Technical
In this round, the interviewers mainly focus on
Your technical Knowledge
Projects that are undertaken by you
The Capgemini Interview questions would first start with the
basics and then there would be an increase in the level of
difficulty. But do note that personal interview questions could
also be asked in this round.
Capgemini Most Asked Technical Interview
Questions:
Questions could be asked based on the subject you choose.
Take the example where you are asked about your favourite
subject.
And you reply by saying either of the subjects. Here are a few
Capgemini most asked interview questions concerning each
subject.
Capgemini Interview Questions - DBMS
If DBMS happens to be your favourite subject then you may
be asked to write SQL queries or you could be asked a few
questions such as
Q1. What is the use of DBMS?
Ans 1. DBMS is also known as Database Management
System. It is an application system wherein its main purpose
is to revolve around data. This allows its user to store the
data, define it, retrieve it and update the information about
the data inside the database.
Q2. What do you mean by Database?
Ans 2. Simply put, Database refers collection of data in some
organized way to facilitate its user’s to easily access, manage
and upload the data.
Q3. Why is the use of DBMS recommended? Explain by listing
any 4 of its major advantages.
Ans 3. Reducing Data Redundancy: DBMS supports a
mechanism to reduce the data redundancy inside the
database by integrating all the data into a single database
and as data is stored at only one place, the duplicity of data
does not happen.
Sharing Data: Sharing data among multiple users can be
done simultaneously in DBMS as the same database will also
be shared among all the users and by different application
programs.
Data Integrity: This means that the data is always accurate
and consistent in the database. It is very important as there
are multiple databases in a DBMS and all of these databases
contain data that happens to be visible to multiple users. So
it is vital to ensure that the data is correct and consistent in
all the databases and for all the users.
Data Security: In data security, only authorised users are
allowed to access the database and their identity should be
authenticated using a valid username and password.
Unauthorised users are not be allowed to access the
database under any circumstances as doing so violates the
integrity constraints.
Q4. What is normalization needed in DBMS?
Ans 4. Normalization is the process of analyzing relational
schemas which are based on their respective functional
dependencies and the primary keys so that they fulfill certain
properties.
Properties:
To minimize data redundancy.
To minimize the anomalies of Insert, Delete and Update.
Q5. Explain the concepts of a Primary key and Foreign Key.
Ans 5. Primary Key uniquely identifies the records in a
database table while Foreign Key, on the other hand, is used
to link two or more tables together.
Example: Consider 2 tables – Employee and Department.
Both have one common field/column as ‘ID’ where ID is the
primary key of the Employee table while this happens to be
the foreign key for the Department table.
Q6. What is the biggest difference between UNION and
UNION ALL?
Ans 6. They are both used to join the data from 2 or more
tables but UNION removes duplicate rows and picks the rows
which are distinct after combining the data from the tables
whereas UNION ALL, unlike UNION, does not remove the
duplicate rows, it just picks all the data from the tables.
Q7. Explain the concept of ACID properties in DBMS?
Ans 7. ACID properties are a combination of Atomicity,
Consistency, Isolation, and Durability properties. These
properties prove to be very helpful in allowing a safe and
secure way of sharing the data amongst multiple users.
Atomicity: When changes are being done to the data it feels
as though a single operation is performed. In other words,
either all the changes are performed, or none of them is
performed.
Consistency: Data must be in a consistent state at the
beginning of the transaction as well as the end of the
transaction.
Isolation: As the name itself suggests, this ensures that
each transaction that occurs is in isolation from others.
Simply put a transaction that has started but not yet
completed should be in isolation with others, this is done so
that the other transaction does not get impacted with this
transaction.
Durability: In the event of system failure, after the
transaction is completed, changes to the data persist and are
not undone. Hence, due to this property data is always in a
durable state.
To Know more Capgemini DBMS Interview Questions, Click
here
Capgemini Interview Questions - Java
Q1. Explain JDK, JRE and JVM?
JDK JRE JVM
JDK stands for Java Development Kit JRE stands for Java Runtime Environment JVM stand
This tool plays an important role in compiling, This refers to a runtime environment where JVM is an a
documenting, and packaging Java programs Java bytecode can be executed environme
JRE happens to be an implementation of the
JDK consists of JRE + development tool JVM follow
JVM which physically exists
Q2. Explain public static void main(String args[]) in Java.
Ans 2. main() in Java refers to the entry point for any Java
program and is always written as public static void
main(String[] args).
public: Public is an access modifier. It is used to specify who
can access this method. Public means that this Method could
be accessed by any Class.
Static: Static is a keyword that identifies it is class-based.
main() is made static in Java so that it can be accessed
without creating the instance of a class but if main is not
made static then the compiler will throw an error as main()
which is then called by the JVM before any objects are made
and only static methods can be directly invoked via the
class.
void: Void refers to the return type of the method and it
defines the method which will not return any value.
main: It is the name of the method which is searched by JVM
as a starting point for an application with a particular
signature only and main is the method where the main
execution occurs.
String args[]: This is the parameter that is passed to the
main method.
Q3. Is Java platform-independent, if yes why?
Ans 4. Yes, Java is platform-independent. This is because for
every operating system present a separate JVM is available
which is capable to read the .class file or byte code.
But while JAVA is a platform-independent language, the JVM is
platform-dependent. Different JVM is designed for different
OS and the byte code is capable of running on different OS.
Q4. What are constructors in Java?
Ans 4. A constructor in Java refers to a block of code which is
used to initialize an object and it must have the same name
as that of the class. Also, a constructor does not have a
return type and it is automatically called when an object is
created.
There are two types of constructors in Java. They are :
Default Constructor: A default constructor does not take
any inputs. In simple terms, default constructors are the no-
argument constructors which will be created by default in
case no other constructor is defined by the user. The main
purpose of a default constructor is to initialize the instance
variables with the default values. Also, it is majorly used for
object creation.
Parameterized Constructor: A parameterized constructor,
unlike the default constructor, is capable of initializing the
instance variables with the provided values. In other words,
the constructors which take the arguments are called
parameterized constructors.
Q5. What is the final keyword in Java?
Ans 5. final is a special keyword in Java and can be used as a
non-access modifier. It could be used in different contexts.
They are given below
the final variable: When the final keyword is used with a
variable then its value can’t be changed and if you consider
the case where no value has been assigned to the final
variable then with the help of the class constructor a value
can be assigned to it.
final method: A simple way to explain the final method is,
when a method is declared final then it can’t be overridden
by the inheriting class.
final class: When you declare a class as final, it can’t be
extended by any subclass class but it can extend other class.
Q6. What is Java String Pool?
Ans 6. It refers to a string collection that is stored in heap
memory.
So, whenever a new object is created, the String pool first
checks whether the object is already present in the pool or
not, and if it is present then the same reference is returned to
the variable.
Otherwise, a new object will be created in the String pool and
the respective reference will be returned.
Q7. Why Java Strings are immutable in nature?
Ans 7. In Java, string objects are immutable in nature.
This means that once the String object is created its state
cannot be modified. So, if you do try to update the value of
that object instead of updating the values of that particular
object, Java creates a new string object.
Java String objects happen to be immutable as String objects
are generally cached in the String pool.
As the String literals are usually shared between multiple
clients, action from one client might affect the rest.
By doing so, it enhances the security, caching,
synchronization, and performance of the application.
To know more Capgemini Java Interview Questions, Click here
Capgemini Interview Questions - C Language
Q1. What are the different storage class specifiers in C?
Ans 1.
auto
register
static
extern
Q2. What is the scope of a variable?
Ans 2. Scope of a variable refers to the part of the program
where the variable may directly be accessible. DO note that
in C, all identifiers are lexically (or statically) scoped.
Q3. What is Dangling pointer?
Ans 3. Dangling Pointer could be defined as a pointer that
doesn’t point to a valid memory location.
Dangling pointers are created when an object is deleted or
deallocated, without modifying the value of the pointer, so
that the pointer still points to the memory location of the
deallocated memory.
Q4. What is a NULL pointer?
Ans 4. A NULL pointer is often used to indicate that the
pointer doesn’t point to a valid location.
In an ideal situation, we should initialize pointers as NULL if
we are not aware of their value at the time of declaration.
Also, a pointer must be made NULL when memory pointed by
it is deallocated in the middle of a program.
Q5. What are the local static variables? What is their use?
Ans 5. A local static variable could be defined as a variable
whose life doesn’t end with a function call where it is
declared.
Local static variable extends for the lifetime of the complete
program.
All calls related to the function do share the same copy of
local static variables.
They can be used to count the number of times a function is
called.
DO note that initially, static variables get the default value is
0.
Q6. What are static functions? What is their use?
Ans 6. Functions happen to be global by default, in C.
The static keyword before a function name makes the
function static.
Access to static functions is restricted to the file where they
are declared as compared to the global functions.
Therefore, to restrict access to functions, we make them
static.
By making functions static, they can reuse the same function
name in other files.
To know more Capgemini C Interview Questions, Click here
Capgemini Interview Questions - Python
Q1. Why is Python needed?
Ans 1. Python is a general-purpose and a high-level
programming language and you could use Python for
developing desktop GUI applications, websites and web
applications.
It lets you focus on the core functionality of the application by
taking care of common programming tasks.
The code in Python is easily readable and maintainable.
It supports multiple programming paradigms
It happens to be compatible with major platforms and
systems
Most importantly Python does have a very robust standard
library
Q2. Where is it used in real life?
Ans 2. Python could be used in:
Game development
Web development
Language development
Operating systems
Image processing
Graphic design applications
Q3. What are the key features of Python?
Ans 3. Python is an interpreted language.
It is dynamically typed
Python functions happen to be first-class objects, in other
words, they can be assigned to variables, returned from other
functions, and passed into functions.
Writing the code in Python is quicker but running it is
comparatively slower than in other languages
It could be used in many spheres of life, such as game
development, web applications, automation, and more.
Q4. How is memory managed in Python?
Ans 4. The memory is managed by Python private heap
space. All Python objects and data structures are located in a
private heap but the programmer does not have access to
this private heap. Instead, this is taken care of by the Python
interpreter.
Python’s memory manager is responsible for the allocation of heap
space for Python objects. The core API then gives access to a few tools
for the programmer to code.
It also has an inbuilt garbage collector, as the name suggests this
basically recycles all the unused memory and so that it can be made
available to the heap space.
Q5. What are modules in Python?
Ans 5. Python modules are could be referred to as files
containing Python code and this code could either be function
classes or variables. Simply put, a Python module is a .py file
containing executable code.
Given below are some of the commonly used built-in
modules:
os
sys
math
random
data time
JSON
Q6. Explain namespace in Python.
Ans 6. Variables are the names or identifiers that map to
objects. Whereas the namespace is a dictionary of variable
names that could also be referred to as keys and their
corresponding objects or values.
A Python statement can access variables in a local as well as
the global namespace. If a local and a global variable have
the same name, then the local variable shadows the global
variable.
Q7. What is a dictionary in Python?
Ans 7. A dictionary in Python is the built-in data type.
A dictionary in Python defines a one-to-one relationship
between keys and values.
They usually do contain a pair of keys and their
corresponding values and are indexed by keys.
To know more Capgemini Python Interview Questions, Click
here
Capgemini Interview Questions - C++
Q1. Briefly explain the concept of Inheritance in C++.
Ans 1. When C++ allows classes to inherit some of the
commonly used states and behaviour from other classes, it is
known as inheritance.
Q2. Define C++
Ans 2. C++ could be defined as a computer programming
language that is a superset of C wherein additional features
are made in the C language.
Q3. Can we call C++ as OOPS? and Why?
Ans 3. Yes, we can call C++ as OOPS. Object-Oriented
Programming System means that it provides an application of
various concepts including data binding, polymorphism,
inheritance, and various others.
Q4. What is the function of the keyword “Volatile”?
Ans 4. Volatile is a function that is used to declare whether
the particular variable is volatile and thereby directs the
compiler to change the variable externally.
This way helps in avoiding the compiler optimization on the
variable reference.
Q5. Define storage class in C++? Name some?
Ans 5. A storage class in C++ specifically resembles that of
life or even the scope of symbols, including the variables,
functions, etc.
Some of the storage classes in C++ are mutable, auto,
static, extern, register, etc.
Q6. Explain ‘this’ pointer?
Ans 6. The ‘this’ pointer could be referred to as a constant
pointer that holds the memory address of the current object.
It passed off as a hidden argument to all the nonstatic
member function calls and is available as a local variable
within the body of all the nonstatic functions.
The static member functions can be called even without any
object, i.e. with the class name, which is why the ‘this’
pointer is not available for them.
Q7. Why do we need the Friend class and function?
Ans 7. At times there is a need for allowing a particular class
to access private or protected members of a class and to do
so we make use of a friend class, that is capable of accessing
the protected as well as the private members of the class in
which it is declared as a friend.
A friend function, on the other hand, can access private and
protected class members. It could either be a global function
or a method of some class.
To know more Capgemini C++ Interview Questions, Click
here
Capgemini Interview Questions - Project Related
Given below are a few questions that could be asked based
on the projects undertaken by you along with a few pointers
that you could keep in mind while answering the questions.
Q1. What is your project about?
Ans 1.
Do show your individuality in the project
You might have worked on several projects, choose the right one.
Instead of giving a long lecture, you should try giving a precise answer
that would cover up all the points.
You could go as far as to add the challenges you faced and where this
could have been applied.
Q2. What are the tools and technologies used in your
project?
Ans 2.
This is a pretty important aspect of your project.
This gives the interviewer a better understanding of your project and
also about its working.
Try making your answer short and to the point.
Q3. The reason behind picking up a particular language for
the project
Ans 3.
This could be answered by talking about the merits of that particular
language. Say, the language could have a good ecosystem, vendor
support is provided, it could integrate with other languages as well, and
more.
It would be advantageous to prepare beforehand the languages you
have used in your project.
Q4. Your role in the project
Ans 4.
Your role could be a small or a big one but the most important thing is
how you portray yourself.
Be specific in terms of actual contributions that you brought to the table
in your project, in terms of how you added value to the main objective
You might want to be modest by telling that it is teamwork but
remember that it is an interview for an individual, not a team.
Capgemini Interview Questions - HR
Capgemini conducts their HR interview round to judge your
personality, strengths and weaknesses, background,
capabilities and most importantly to see if you are the right
person for the job. Once you have passed the Capgemini
technical interview you will then get the opportunity to
attempt the Capgemini HR interview.
Questions that could be asked during the HR round
are:
Q1. Tell me about yourself.
Ans 1. This question is asked to ease the candidate into the
actual interview. Here are a few pointers that could help you
while answering this.
Be succinct. Or in layman’s terms don’t waste your time regurgitating
every single detail of your life.
Keep it professional but do inject some passion into your answer, this
helps in engaging the interviewer and also sets you apart from the rest.
Try structuring your answer. You could first start with the present i.e
your current achievements, then the past that could consist of previous
experience relevant to the job. Finally, the future could include what you
are looking for and why you are interested in the job.
Remember, your answer will help the interviewer find their next
question.
Q2. What’s your family background?
Ans 2.
You must prepare for this question instead of fumbling.
Try to show good values that have been inculcated in you by your
parents
You could even add a few things that have been taught to you by your
family.
Q3. Why choose Capgemini?
Ans 3.
To answer this question you will have to do your research on the
company
This question gives the interviewer the perfect opportunity to find more
about your career goals and how this job role will fit your plan.
You could highlight a few points on the company’s general reputation,
admiration for the products and services offered by the company, the
company values and other initiatives taken by the company.
Q4. Are you comfortable with reallocation?
Ans 4.
You could give a positive answer if you are willing to relocate anywhere
they would like
This would show that you would do anything necessary to be a part of
the company and the team
Moving isn’t exactly the best situation that you could be in, even though
the job opportunity is exactly what you’re looking for. Be confident while
you are answering and if you do have queries about this, you could ask.
Q5. What is the toughest decision that you have made in
your life?
Ans 5.
The interviewer asks this question to see how well you can handle
stressful situations.
This question could also be a good judge of your critical thinking skills
Firstly, pick the right challenge
Then discuss your options, how you weighed them and what made you
choose one of them.
This should exhibit your ability to remain calm and solve problems in a
difficult situation.
Q6. Have you had any gaps in your academic years?
Ans 6.
If you haven’t had a gap during your academic years you could simply
say no. But if you have had gaps in your academic years, here’s how
you could reply.
Give the interviewer a simple explanation of what you did during your
gap year.
The reasoning behind your gap year proves to be compelling for an
interview.
You could then further explain how your gap year helped you gain
invaluable skills.
Q7. Did you work as a team leader?
Ans 7.
You could give an example that exhibits your decision and problem-
solving skills
In the Capgemini Interview Round, questions could be asked
depending on the subject you choose. Consider the example
where you are asked about your favourite subject.
And if you reply by saying DBMS then you may be asked to
write SQL queries or you could be asked a few questions.
To know more about Capgemini Recruitment Proces, Click
here
Given below are a few Capgemini Interview Questions on
DBMS.
Capgemini DBMS Interview Questions
Q1. What is the use of DBMS?
Ans 1. DBMS is also known as Database Management
System. It is an application system wherein its main purpose
is to revolve around data. This allows its user to store the
data, define it, retrieve it and update the information about
the data inside the database.
Q2. What do you mean by Database?
Ans 2. Simply put, Database refers collection of data in some
organized way to facilitate its user’s to easily access, manage
and upload the data.
Q3. Why is the use of DBMS recommended? Explain by listing
any 4 of its major advantages.
Ans 3. Reducing Data Redundancy: DBMS supports a
mechanism to reduce the data redundancy inside the
database by integrating all the data into a single database
and as data is stored at only one place, the duplicity of data
does not happen.
Sharing Data: Sharing data among multiple users can be
done simultaneously in DBMS as the same database will also
be shared among all the users and by different application
programs.
Data Integrity: This means that the data is always accurate
and consistent in the database. It is very important as there
are multiple databases in a DBMS and all of these databases
contain data that happens to be visible to multiple users. So
it is vital to ensure that the data is correct and consistent in
all the databases and for all the users.
Data Security: In data security, only authorised users are
allowed to access the database and their identity should be
authenticated using a valid username and password.
Unauthorised users are not be allowed to access the
database under any circumstances as doing so violates the
integrity constraints.
Q4. What is normalization needed in DBMS?
Ans 4. Normalization is the process of analyzing relational
schemas which are based on their respective functional
dependencies and the primary keys so that they fulfil certain
properties.
Properties:
To minimize data redundancy.
To minimize the anomalies of Insert, Delete and Update.
Q5. Explain the concepts of a Primary key and Foreign Key.
Ans 5. Primary Key, uniquely identifies the records in a
database table while Foreign Key, on the other hand, is used
to link two or more tables together.
Example: Consider 2 tables – Employee and Department.
Both have one common field/column as ‘ID’ where ID is the
primary key of the Employee table while this happens to be
the foreign key for the Department table.
Q6. What is the biggest difference between UNION and
UNION ALL?
Ans 6. They are both used to join the data from 2 or more
tables but UNION removes duplicate rows and picks the rows
which are distinct after combining the data from the tables
whereas UNION ALL, unlike UNION, does not remove the
duplicate rows, it just picks all the data from the tables.
Q7. Explain the concept of ACID properties in DBMS?
Ans 7. ACID properties are a combination of Atomicity,
Consistency, Isolation, and Durability properties. These
properties prove to be very helpful in allowing a safe and
secure way of sharing the data amongst multiple users.
Atomicity: When changes are being done to the data it feels
as though a single operation is performed. In other words,
either all the changes are performed, or none of them is
performed.
Consistency: Data must be in a consistent state at the
beginning of the transaction as well as the end of the
transaction.
Isolation: As the name itself suggests, this ensures that
each transaction that occurs is in isolation with others. Simply
put a transaction which has started but not yet completed
should be in isolation with others, this is done so that the
other transaction does not get impacted with this transaction.
Durability: In the event of system failure, after the
transaction is completed, changes to the data persist and are
not [Link], due to this property data is always in a
durable state.
Capgemini Java Interview Questions
Q1. Explain JDK, JRE and JVM?
JDK JRE JVM
JDK stands for Java Development Kit. JRE stands for Java Runtime Environment. JVM stands
This tool plays an important role in compiling, This refers to a runtime environment where Java JVM is an a
documenting and packaging Java programs. bytecode can be executed. environme
JRE happens to be an implementation of the
JDK consists of JRE + development tool. JVM follow
JVM which physically exists.
Q2. Explain public static void main(String args[]) in Java.
Ans 2. main() in Java refers to the entry point for any Java
program and is always written as public static void
main(String[] args).
public: Public is an access modifier. It is used to specify who
can access this method. Public means that this Method could
be accessed by any Class.
Static: Static is a keyword that identifies it is class-based.
main() is made static in Java so that it can be accessed
without creating the instance of a class but if main is not
made static then the compiler will throw an error as main()
which is then called by the JVM before any objects are made
and only static methods can be directly invoked via the
class.
void: Void refers to the return type of the method and it
defines the method which will not return any value.
main: It is the name of the method which is searched by JVM
as a starting point for an application with a particular
signature only and main is the method where the main
execution occurs.
String args[]: This is the parameter that is passed to the
main method.
Q3. Is Java platform-independent, if yes why?
Ans 4. Yes, Java is platform-independent. This is because for
every operating system present a separate JVM is available
which is capable to read the .class file or byte code.
But while JAVA is a platform-independent language, the JVM is
platform-dependent. Different JVM is designed for different
OS and the byte code is capable of running on different OS.
Q4. What are constructors in Java?
Ans 4. A constructor in Java refers to a block of code which is
used to initialize an object and it must have the same name
as that of the class. Also, a constructor does not have a
return type and it is automatically called when an object is
created.
There are two types of constructors in Java. They are :
Default Constructor: A default constructor does not take
any inputs. In simple terms, default constructors are the no-
argument constructors which will be created by default in
case no other constructor is defined by the user. The main
purpose of a default constructor is to initialize the instance
variables with the default values. Also, it is majorly used for
object creation.
Parameterized Constructor: A parameterized constructor,
unlike the default constructor, is capable of initializing the
instance variables with the provided values. In other words,
the constructors which take the arguments are called
parameterized constructors.
Q5. What is the final keyword in Java?
Ans 5. final is a special keyword in Java and can be used as a
non-access modifier. It could be used in different contexts.
They are given below
final variable: When the final keyword is used with a
variable then its value can’t be changed and if you consider
the case where no value has been assigned to the final
variable then with the help of the class constructor a value
can be assigned to it.
final method: A simple way to explain the final method is,
when a method is declared final then it can’t be overridden
by the inheriting class.
final class: When you declare a class as final, it can’t be
extended by any subclass class but it can extend other class.
Q6. What is Java String Pool?
Ans 6. It refers to a string collection that is stored in heap
memory.
So, whenever a new object is created, the String pool first
checks whether the object is already present in the pool or
not and if it is present then the same reference is returned to
the variable.
Otherwise, a new object will be created in the String pool and
the respective reference will be returned.
Q7. Why Java Strings are immutable in nature?
Ans 7. In Java, string objects are immutable in nature.
This means that once the String object is created its state
cannot be modified. So, if you do try to update the value of
that object instead of updating the values of that particular
object, Java creates a new string object.
Java String objects happen to be immutable as String objects
are generally cached in the String pool.
As the String literals are usually shared between multiple
clients, action from one client might affect the rest.
By doing so, it enhances security, caching, synchronization,
and performance of the application.