Programming Logic
Question 1
Answer
Question 1
When we compose a binary tree through the given preorder sequence, what will be left child of 6? (Note: Consider 4 as root node)
4, 2, 1, 3, 6, 5, 7
A. 1
B. 5
C. 7
D. 3
Answer
B. 5
Question 2
Answer
Question 2
Based on below infix and postfix expressions, identify the Prefix expression.
Infix expression: P-Q-(R+S)/(W-X)*Y+Z
Postfix Expression: PQRS+*WX-Y*/Z+
A. -P/*Q+RS+*-WXYZ
B. -P/*Q+RS+*W-XYZ
C. P-/*Q+R+S*WXYZD. P-/*+RS+Q*-WXYZ
Answer
All the answer options are wrong.
Correct Answer: -P-Q+/+RS*-WXYZ. Best similar answer can be option A
Question 3
Answer
Question 3
In a Singly Circular Linked List, how many address fields are there?
A. 1+1
B. 2+1
C. 1
D. 2
Answer
C. 1
Question 4
Answer
Question 4
Which of the following is NOT a logical operator?
A. !
B. &&
C. ||
D. &
Answer
D. &
Question 5
Answer
Question 5
The data modelling phase consists of which of the following?
A. Creation of evaluation tool
B. Creation of big data analysis model
C. Creation of infographics
D. Creation of the logical data model.
Answer
D. Creation of the logical data model.
Also Checkout: TCS NQT Sample Question Paper
Question 6
Answer
Question 6
Select the best suitable answer for the below functions.
1. sizeof()
2. strlen
A. sizeof() – Returns size of string including null characters
strlen() – Returns size of string excluding null characters
B. sizeof() – Returns size of string including null characters
strlen() – Returns size of string including null characters
C. sizeof() – Returns size of string excluding null characters
strlen() – Returns size of string excluding null, characters
D. sizeof() – Returns size of string excluding null characters
strlen() – Returns size of string including null characters
Answer
A. sizeof() – Returns size of string including null characters
ustrlen() – Returns size of string excluding null characters
public class Main
{
int x = 10;
public static void main(String [] args)
{
try
{
Main t1 = new Main();
System.out.println(t1.x);
}
catch(Exception e)
{
System.out.println("exception Caught");
return;
}
}
static
{
int x = 20;
System.out.println(x+" ");
}
}
Question 7
Answer
Explanation
Question 7
What will be the output of the above code?
Answer
20
10
Explanation
static block is executed at first, then main function.
TCS NQT MOCK TEST / PRACTICE AET
Click Here!
void main()
{
char a[10][10] = {"kellos", "hellos", "fellos"};
print("%s", a[i]);
}
Question 8
Answer
Question 8
What will be the output of the above program?
A. Compile time error
B. ellos hellos fellos
C. ellos
D. hellos
Answer
D. hellos
public class Main
{
public static void main(string[] args)
{
try
{
int[] arr = {10,25,2,6,8,9,7,32};
for(int i=0; i<arr.length; i++)
{
System.out.print(arr[i+1]);
}
}
catch(Exception e)
{
System.out.println("Inside Exception");
}
}
}
Question 9
Answer
Question 9
What will be the output of the following program?
Answer
252689732Inside Exception
class car
{
public vpid Show()
{
System.out.println("Brand is not defined yet");
}
}
class mercedes extend car
{
public void Show()
{
System.out.println("It's mercedes");
}
}
class Benz extends mercedes
{
}
public class Main
{
public static void main(String[]args)
{
car obj = new Benz();
obj.Show();
}
}
Question 10
Answer
Explanation
Question 10
What will be the output?
A. It’s mercedes
B. Run Time Error
C. Compile Time Error
D. Brand is not defined yet
Answer
A. It’s mercedes
Explanation
It’s runtime polymorphism. show() is not found in Benz Class so it searched in It’s parent Mercedes and found.
Also Checkout