
Programming Logic
import java.util.*;
public class Main
{
public static void main(String[] args)
{
ArrayListTempArrayList = new ArrayList();
TempArrayList.add(30);
TempArrayList.add(20);
TempArrayList.add(10);
TempArrayList.add(40);
TempArrayList.add(50);
Collections.sort(TempArrayList, Collections.reverseOrder());
Collections.sort(TempArrayList, Collections.reverseOrder());
System.out.println(TempArrayList);
}
}
Question 1
Answer
Explanation
Question 1
What will be the output of the above program?
Answer
[50, 40, 30, 20, 10]
Explanation
Collections.sort(TempArrayList, Collections.reverseOrder()) sorts the array in descending order everytime.
public class Main
{
public static void main(String args[])
{
int x=10,y,z;
z=y=x;
y-= x --;
z-=--x;
x-= --x - x--;
System.out.println(x+"-"+y+"-"+z);
}
}
Question 2
Answer
Explanation
Question 2
What will be the output of the above program?
Answer
8-0-2
Explanation
First x,y and z all are assigned 10.
y-= x –; // y = y-x– => y = 10-10 = 0 [After execution x becomes 9]
z-=–x; // z = z- –x => z = 10 – 8 = 2 [x becomes 8]
x -= –x – x–; // x = x – (–x – x–) => x = 8 – (7 – 7) = 8 [8 is stored in x]
Question 3
Answer
Question 3
float (*p)[5]
Here, p is ______________
A. Pointer to array of float
B. Float
C. Array of pointer
D. Pointer
Answer
C. Array of pointer
TCS NQT MOCK TEST / PRACTICE AET
Click Here!
Question 4
Answer
Question 4
What is the function of rewind()?
A. Setting file pointer at the beginning of line
B. Setting file pointer anywhere in file
C. Setting file pointer at the end of file
D. Setting file pointer at the beginning of file
Answer
D. Setting file pointer at the beginning of file
abstract class Shape{
public abstract void Disp();
}
class Triangle extends Shape{
public final void Disp(){
System.out.println("It's Rectangle");
}
}
public class Main{
public static void main(String [] args){
Rectangle obj = new Rectangle();
obj.Disp();
}
}
Question 5
Answer
Question 5
What will be the output of the above program?
A. Run time error
B. Triangle
C. Compile Time error
D. It’s Rectangle
Answer
C. Compile Time error
TCS NQT MOCK TEST / PRACTICE AET
Click Here!
Question 6
Answer
Question 6
Select the precise options for the below scenarios
Expression 1: cout<<endl;
Expression 1: cout<<”\n”<<flush;
A. Second expression will not insert new line
B. First expression will not insert new line
C. Both expression will give same results
D. Both expression will give different results
Answer
C. Both expression will give same results
Question 7
Answer
Question 7
The kind of software testing you can do when you have both the source code and the executable code in hand, is called as?
A. Red Box Testing
B. Black Box Testing
C. White Box Testing
D. Blue Box Testing
Answer
C. White Box Testing
Question 8
Answer
Question 8
Consider the following variables declarations:
Float num1;
Short num2;
Long num3;
What is the data type of num1-num3/num2?
A. None of the given options
B. Float
C. Double
D. Short
Answer
B. Float
Question 9
Answer
Question 9
Construct post order Transversal for the constructed tree with the given In-Order and Preorder Traversals:
In-Order: 9 7 10 6 8
Pre-Order: 6 7 9 10 8
A. 9 10 7 8 6
B. 9 7 6 10 8
C. 8 9 10 7 6
D. 9 8 10 7 6
Answer
A. 9 10 7 8 6
Also Checkout