1.
Why is progamming important today?
2.
Why do you want to do internship?
3.
A memory location that holds a single letter or number.
Correct Answer
C. Char
Explanation
A char is a data type in programming that represents a single letter or number. It is used to store characters such as letters, digits, and symbols. In memory, a char variable occupies a single memory location, making it suitable for storing a single character. The other data types mentioned in the options, such as double and int, are used to store numbers with different precision and range. The option "word" is not a valid data type in most programming languages.
4.
A do while and a while loop are the same
Correct Answer
B. False
Explanation
A do-while loop and a while loop are not the same. The main difference between them is that a while loop checks the condition before executing the loop, while a do-while loop checks the condition after executing the loop. This means that a do-while loop will always execute at least once, regardless of the condition being true or false. In contrast, a while loop may not execute at all if the condition is initially false. Therefore, the correct answer is False.
5.
A short sections of code written to complete a task.
Correct Answer
C. Function
Explanation
A function is a short section of code that is written to perform a specific task. It is a reusable block of code that can be called multiple times throughout a program to execute the same set of instructions. Functions help to organize and modularize code, making it easier to read, understand, and maintain. They are typically defined with a name, a set of input parameters (optional), and a return value (optional). Thus, a function fits the description of a short section of code written to complete a task.
6.
Int hold decemals numbers
Correct Answer
B. False
Explanation
This statement is incorrect because the word "decemals" is misspelled. The correct spelling is "decimals." Therefore, the correct answer is False.
7.
What is FIFO?
Correct Answer
C. First In First Out
Explanation
FIFO stands for "First In First Out." It is a method of organizing and manipulating data where the first item that is inserted or added into a data structure is the first one to be removed or processed. This concept is commonly used in various fields, such as computing, inventory management, and queueing systems. It ensures that items are processed or handled in the order they arrive, maintaining the chronological order of the data.
8.
What dose this equation mean ?
a != t
Correct Answer
C. A is not equal to t
Explanation
The equation "a != t" means that variable a is not equal to variable t. It is a comparison statement indicating that the values assigned to a and t are different.
9.
One loop inside the body of another loop is called
Correct Answer
B. Nested
Explanation
When one loop is placed inside the body of another loop, it is referred to as a nested loop. The outer loop controls the number of times the inner loop will execute. This allows for more complex and intricate looping structures, where the inner loop can perform a set of actions multiple times within each iteration of the outer loop. The term "nested" is used because the loops are visually represented as being inside one another, similar to how nesting dolls fit inside each other.
10.
Which data structure uses LIFO?
Correct Answer
C. Stacks
Explanation
Stacks use the LIFO (Last-In-First-Out) principle, where the last element added to the stack is the first one to be removed. This means that when an element is inserted into a stack, it is placed on top of the previously inserted elements. When an element is removed from the stack, the topmost element is removed first. This behavior is similar to a stack of plates, where the last plate placed on top is the first one to be removed. Therefore, the correct answer is Stacks.
11.
Entering Comments is a useless task, it will not help in anyway.
Correct Answer
B. False
Explanation
The given statement suggests that entering comments is a useless task and will not help in any way. The correct answer is "False" because entering comments can be helpful in various ways. Comments can provide additional information, explanations, or clarifications, making the code more understandable for other programmers. They can also serve as reminders or notes for the developer themselves, helping them remember the purpose or functionality of certain code sections. Therefore, entering comments can be a valuable practice in programming.
12.
A Syntax Error is ?
Correct Answer
C. An error caused by language rules being broken.
Explanation
A Syntax Error is an error caused by language rules being broken. Syntax refers to the rules and structure of a programming language. When these rules are violated, such as using incorrect syntax or missing semicolons, the program will not be able to execute properly and will throw a syntax error. This type of error can be easily identified by the compiler or interpreter, as it is a violation of the language's syntax rules.
13.
What command do you use to output data to the screen?
Correct Answer
C. Cout
Explanation
The correct answer is "cout". In C++, "cout" is a standard output stream object that is used to display output on the screen. It is commonly used with the insertion operator "
14.
Two main measures for the efficiency of an algorithm are
Correct Answer
C. Time and space
Explanation
The efficiency of an algorithm is typically measured by its time complexity and space complexity. Time complexity refers to the amount of time it takes for the algorithm to run, while space complexity refers to the amount of memory or space required by the algorithm to solve a problem. Therefore, the correct answer is "Time and space" as these two measures are commonly used to evaluate the efficiency of an algorithm.
15.
The time factor when determining the efficiency of algorithm is measured by
Correct Answer
B. Counting the number of key operations
Explanation
The efficiency of an algorithm is determined by counting the number of key operations it performs. Key operations refer to the fundamental steps or operations that the algorithm needs to execute in order to solve a problem. By counting these key operations, we can get an idea of the time complexity of the algorithm, which helps us understand how the algorithm will perform as the input size increases. Counting microseconds, the number of statements, or the kilobytes of the algorithm are not accurate measures of the time factor in determining efficiency.
16.
The space factor when determining the efficiency of algorithm is measured by
Correct Answer
A. Counting the maximum memory needed by the algorithm
Explanation
The space factor when determining the efficiency of an algorithm is measured by counting the maximum memory needed by the algorithm. This means that the efficiency of the algorithm is evaluated based on the maximum amount of memory it requires to execute. By considering the maximum memory usage, we can assess how well the algorithm performs in terms of space utilization. This information is crucial for optimizing the algorithm and ensuring that it can run efficiently within the available memory resources.
17.
Which of the following case does not exist in complexity theory
Correct Answer
D. Null case
Explanation
The null case does not exist in complexity theory because it refers to a scenario where there is no input or no operations to be performed. In complexity theory, the focus is on analyzing the performance of algorithms in different scenarios, such as best case, worst case, and average case, where there is input and operations to be considered. The null case is not relevant in this context as it does not involve any input or operations to analyze.
18.
The Worst case occur in linear search algorithm when
Correct Answer
D. Item is the last element in the array or is not there at all
Explanation
In linear search, the algorithm starts searching from the beginning of the array and continues until it finds the desired item or reaches the end of the array. In the worst case scenario, the item being searched for is either the last element in the array or not present at all. If the item is the last element, the algorithm will have to iterate through the entire array before finding it. Similarly, if the item is not present in the array, the algorithm will have to search through the entire array without finding it. In both cases, the worst case time complexity is O(n), where n is the size of the array.
19.
The Average case occur in linear search algorithm
Correct Answer
A. When Item is somewhere in the middle of the array
Explanation
The average case in linear search occurs when the item being searched for is somewhere in the middle of the array. In this case, the algorithm will need to iterate through approximately half of the array before finding the item. This is because linear search checks each element of the array one by one until it either finds the item or reaches the end of the array. Therefore, on average, the algorithm will need to iterate through half of the array to find the desired item.
20.
The complexity of the average case of an algorithm is
Correct Answer
A. Much more complicated to analyze than that of worst case
Explanation
The complexity of the average case of an algorithm is much more complicated to analyze than that of the worst case because it requires considering a range of possible inputs and their probabilities. The worst case complexity only considers the maximum possible input size, while the average case complexity takes into account the likelihood of different input sizes and distributions. This makes the analysis of average case complexity more complex and time-consuming compared to the worst case.
21.
The complexity of linear search algorithm is
Correct Answer
A. O(n)
Explanation
The complexity of the linear search algorithm is O(n) because it has to iterate through each element in the list until it finds the desired element or reaches the end of the list. This means that the time it takes to complete the algorithm grows linearly with the size of the input.
22.
The complexity of Binary search algorithm is
Correct Answer
B. O(log )
23.
The complexity of Bubble sort algorithm is
Correct Answer
C. O(n2)
Explanation
Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The algorithm has a time complexity of O(n2), which means that the number of operations required to sort the list is proportional to the square of the number of elements in the list. This is because in the worst case scenario, where the list is in reverse order, each element needs to be compared with every other element, resulting in n comparisons for each of the n elements. Therefore, the time complexity is O(n2).
24.
The complexity of merge sort algorithm is
Correct Answer
D. O(n log n)
Explanation
The complexity of merge sort algorithm is O(n log n) because it divides the input array into two halves, recursively sorts them, and then merges the two sorted halves. The time complexity of merging two sorted arrays of size n/2 each is O(n), and the time complexity of dividing the array into halves is O(log n). Hence, the overall time complexity is O(n log n).
25.
The indirect change of the values of a variable in one module by another module is called
Correct Answer
C. Side effect
Explanation
Side effect refers to the indirect change of the values of a variable in one module by another module. It occurs when a module modifies the state of a variable that is accessible by another module, resulting in an unintended change in behavior. This can lead to unexpected consequences and can make the code harder to understand and maintain. Therefore, the term "side effect" accurately describes this situation.
26.
Which of the following data structure is not linear data structure?
Correct Answer
D. None of above
Explanation
The correct answer is "None of above". This means that both arrays and linked lists are linear data structures. Arrays store elements in contiguous memory locations, allowing for efficient random access. Linked lists, on the other hand, store elements in separate nodes that are connected through pointers, allowing for efficient insertion and deletion operations. Therefore, both arrays and linked lists are examples of linear data structures.
27.
Which of the following data structure is linear data structure?
Correct Answer
C. Arrays
Explanation
Arrays are a linear data structure because they store elements in a sequential manner. Each element in an array can be accessed by its index, which represents its position in the array. This allows for efficient traversal and retrieval of elements. Arrays have a fixed size and elements are stored contiguously in memory, making them suitable for tasks such as sorting and searching. Trees and graphs, on the other hand, are non-linear data structures as they allow for more complex relationships between elements.
28.
The operation of processing each element in the list is known as
Correct Answer
D. Traversal
Explanation
Traversal refers to the process of accessing each element in a list or data structure one by one. It involves visiting and examining each element without changing their order or structure. In this context, the operation of processing each element in the list is referred to as traversal. Sorting involves rearranging the elements in a specific order, merging combines two or more lists into a single list, and inserting involves adding an element at a specific position in the list.
29.
Finding the location of the element with a given value is:
Correct Answer
B. Search
Explanation
The correct answer is "Search" because finding the location of an element with a given value involves searching through a data structure or collection to locate the desired element. Traversal refers to the process of accessing each element in a data structure, while sorting involves arranging elements in a specific order. Therefore, "Search" is the most appropriate term for finding the location of an element with a given value.
30.
Arrays are best data structures
Correct Answer
A. For relatively permanent collections of data
Explanation
Arrays are best data structures for relatively permanent collections of data because arrays have a fixed size and are suitable for storing a fixed number of elements. They provide efficient random access to elements and have a simple and straightforward implementation. However, arrays are not suitable for situations where the size of the structure and the data in the structure are constantly changing, as arrays cannot dynamically resize themselves. Therefore, the correct answer is that arrays are best for relatively permanent collections of data.
31.
Linked lists are best suited
Correct Answer
B. for the size of the structure and the data in the structure are constantly changing
Explanation
Linked lists are best suited for situations where the size of the structure and the data in the structure are constantly changing. This is because linked lists allow for efficient insertion and deletion of elements at any position in the list, without the need to shift or resize the entire structure. Unlike arrays, which have a fixed size, linked lists can dynamically adjust their size to accommodate changes in the data. This makes linked lists a flexible and efficient choice for managing collections of data that are constantly being modified.
32.
Each array declaration need not give, implicitly or explicitly, the information about
Correct Answer
C. The first data from the set to be stored
Explanation
The first data from the set to be stored is not required to be specified in the array declaration. The array declaration only needs to include the name of the array and the data type of the array. The first data from the set to be stored can be assigned later when the array is initialized or when values are assigned to specific indices of the array.
33.
The elements of an array are stored successively in memory cells because
Correct Answer
A. By this way computer can keep track only the address of the first element and the addresses of other elements can be calculated
Explanation
The elements of an array are stored successively in memory cells because by this way the computer can keep track only the address of the first element and the addresses of other elements can be calculated. This allows for efficient memory management and easy access to array elements by using indexing based on the address of the first element. Storing elements in a serial manner also aligns with the architecture of computer memory, making it a suitable approach for array storage.
34.
Which four options describe the correct default values for array elements of the types indicated?
-
int -> 0
-
String -> "null"
-
Dog -> null
-
char -> '\u0000'
-
float -> 0.0f
-
boolean -> true
Correct Answer
B. 1,3,4,5
Explanation
The correct default values for array elements of the given types are as follows:
1. For int, the default value is 0.
3. For String, the default value is "null".
4. For Dog (a reference type), the default value is null.
5. For char, the default value is '\u0000' (null character).
Therefore, the correct options that describe the default values for array elements of the indicated types are 1, 3, 4, and 5.
35.
Which three are valid declarations of a char?
-
char c1 = 064770;
-
char c2 = 'face';
-
char c3 = 0xbeef;
-
char c4 = \u0022;
-
char c5 = '\iface';
-
char c6 = '\uface';
Correct Answer
B. 1,3,6
36.
Public class Outer
{
public void someOuterMethod()
{
//Line 5
}
public class Inner { }
public static void main(String[] argv)
{
Outer ot = new Outer();
//Line 10
}
}
Which of the following code fragments inserted, will allow to compile?
Correct Answer
A. New Inner(); //At line 5
Explanation
The code fragment "new Inner(); //At line 5" will allow the code to compile because it creates a new instance of the Inner class within the someOuterMethod() method of the Outer class. Since the Inner class is a member of the Outer class, it can be accessed and instantiated within the method.
37.
Which cause a compiler error? (choose all that apply)
Correct Answer(s)
A. Float[ ] f = new float(3);
B. Float f2[ ] = new float[ ];
Explanation
The correct answers are "float[ ] f = new float(3);" and "float f2[ ] = new float[ ];".
The first line of code tries to initialize an array of floats with the size of 3 using the incorrect syntax. The correct syntax for initializing an array with a specific size is "new float[3]".
The second line of code tries to declare an array of floats without specifying the size. In Java, when declaring an array, the size must be specified. Therefore, the correct syntax for declaring an array without specifying the size would be "float[] f2;".
38.
Public class Runner
{
public static void main(String args[])
{
System.out.println(“This is a correct program”);
continue;
}
}
State True or False: The above program prints a output
Correct Answer
B. False
Explanation
The above program will not compile because the continue statement is used outside of a loop. The continue statement is used to skip the current iteration of a loop and move to the next iteration. Since there is no loop in the program, the continue statement is invalid and will result in a compilation error. Therefore, the program will not print any output.
39.
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
Correct Answer
B. Tiny
Explanation
The output of the program will be "tiny". This is because the ternary operator is used to assign the value of the variable "sup". The condition (x < 15) evaluates to false, so the next condition (x < 22) is checked. Since x is equal to 20, this condition is true and the value "tiny" is assigned to "sup". Therefore, "tiny" is printed as the output.
40.
What will be the output of the program?
class Bitwise
{
public static void main(String [] args)
{
int x = 11 & 9;
int y = x ^ 3;
System.out.println( y | 12 );
}
}
Correct Answer
D. 14
Explanation
The program first performs a bitwise AND operation between 11 and 9, resulting in the value 9. Then, it performs a bitwise XOR operation between the result (9) and 3, resulting in the value 10. Finally, it performs a bitwise OR operation between the result (10) and 12, resulting in the value 14. Therefore, the output of the program will be 14.
41.
What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() {}
}
Correct Answer
C. ACD
Explanation
The program will output "ACD". The main method calls the badMethod() method, which is empty and does nothing. Since there is no exception thrown in the try block, the catch block is not executed. The finally block is always executed, so "C" is printed. After the finally block, "D" is printed. Therefore, the output is "ACD".
42.
Public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
Which statement is true?
Correct Answer
A. Compilation fails
Explanation
The compilation fails because the if statement on line 4 requires a boolean expression inside the parentheses. However, the variable "odd" is an integer, not a boolean. To fix this, the if statement should be written as "if(odd != 0)" to check if the value of "odd" is not equal to zero.
43.
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
State True or False: The output of the above code is the below
Exception
finished
Correct Answer
B. False
Explanation
The output of the above code is "Arithmetic Exception" followed by "finished". This is because the code attempts to divide 5 by 0, which results in an ArithmeticException being thrown. Since the catch block for ArithmeticException comes before the catch block for Exception, it is the one that catches the exception and prints "Arithmetic Exception". After the catch blocks, the code continues to execute and prints "finished". Therefore, the correct answer is False.
44.
Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?
Correct Answer
B. Java.util.LinkedHashMap
Explanation
A LinkedHashMap in Java allows you to associate its elements with key values, meaning you can store objects with specific keys. It also allows you to retrieve objects in FIFO sequence, meaning the elements are returned in the order they were added to the map. This makes it a suitable choice for scenarios where both key-value associations and maintaining insertion order are important.
45.
/* Missing Statement ? */
public class foo
{
public static void main(String[]args)throws Exception
{
java.io.PrintWriter out = new java.io.PrintWriter();
new java.io.OutputStreamWriter(System.out,true);
out.println("Hello");
}
}
What line of code should replace the missing statement to make this program compile?
Correct Answer
A. No statement required.
Explanation
The missing statement is not required because the program already includes the necessary import statements for the PrintWriter class. The PrintWriter object "out" is already declared and initialized correctly, so no additional statement is needed.
46.
Which of the following are Java reserved words?
Correct Answer(s)
B. Null
C. Default
Explanation
The correct answer is "null" and "default". In Java, "null" is a reserved word that represents the absence of a value, while "default" is a reserved word used in switch statements to specify the default case. "constant" and "implement" are not reserved words in Java.
47.
State the below statement is not false about static nested class:
It’s variables and methods must be static
Correct Answer
B. False
Explanation
The statement is not false about static nested class. The variables and methods of a static nested class can be either static or non-static.
48.
Class X implements Runnable
{
public static void main(String args[])
{
/* Missing code? */
}
public void run() {}
}
Which of the following line of code is suitable to start a thread ?
Correct Answer
C. X run = new X(); Thread t = new Thread(run); t.start();
Explanation
The correct answer is "X run = new X(); Thread t = new Thread(run); t.start();". This line of code creates an instance of the class X and then creates a new thread using that instance. The thread is then started using the start() method.
49.
Which three guarantee that a thread will leave the running state?
-
yield()
-
wait()
-
notify()
-
notifyAll()
-
sleep(1000)
-
aLiveThread.join()
-
Thread.killThread()
Correct Answer
B. 2,5 and 6
50.
Public class X
{
public static void main(String [] args)
{
X x = new X();
X x2 = m1(x); /* Line 6 */
X x4 = new X();
x2 = x4; /* Line 8 */
doComplexStuff();
}
static X m1(X mx)
{
mx = new X();
return mx;
}
}
After line 8 runs. how many objects are eligible for garbage collection?
Correct Answer
B. 1
Explanation
After line 8 runs, there is only 1 object eligible for garbage collection. This is because the object created in line 6 (referenced by x2) is reassigned to x4 in line 8. Therefore, the object that was originally referenced by x2 is no longer accessible and can be garbage collected. The other objects (referenced by x and x4) are still in use and cannot be garbage collected.