Coder's Challenge Group B (Round 1)

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Prateek
P
Prateek
Community Contributor
Quizzes Created: 1 | Total Attempts: 88
| Attempts: 88 | Questions: 62
Please wait...
Question 1 / 62
0 %
0/100
Score 0/100
1. Which option is best to eliminate the memory problem? 

Explanation

Using smart pointers and a virtual destructor is the best option to eliminate the memory problem. Smart pointers automatically manage the lifetime of dynamically allocated objects by deallocating the memory when it is no longer needed, thus preventing memory leaks. Additionally, using a virtual destructor ensures that the correct destructor is called when deleting an object through a pointer to its base class, preventing undefined behavior and potential memory leaks in polymorphic classes. Together, these two techniques provide a robust solution for managing memory and preventing memory-related issues.

Submit
Please wait...
About This Quiz
Coders Challenge Group B (Round 1) - Quiz

Coder's Challenge Group B (Round 1) assesses programming skills through various questions covering database connections, C++ and Java programming, and logical reasoning. It tests understanding of syntax, threading,... see moreand output prediction, essential for competitive programming. see less

2. What is the output of this program?      #include <iostream>      using namespace std;      int main()      {          int i;          for (i = 0; i < 10; i++);          {              cout << i;          }          return 0;      } 

Explanation

The given program will output the numbers from 0 to 9. This is because the for loop will execute 10 times, with the variable i starting from 0 and incrementing by 1 each time until it reaches 9. Inside the loop, the value of i is printed using the cout statement. After the loop completes, the program will terminate and return 0.

Submit
3. What is the output of this program?     class exception_handling      {         public static void main(String args[])          {             try              {                 int a[] = {1, 2,3 , 4, 5};                 for (int i = 0; i < 7; ++i)                      System.out.print(a[i]);             }             catch(ArrayIndexOutOfBoundsException e)              {             System.out.print("0");                         }         }     }

Explanation

The program initializes an integer array with values 1, 2, 3, 4, 5. It then tries to print the elements of the array using a for loop. However, the loop condition is set to i

Submit
4. What is the output of this program?      #include <iostream>      using namespace std;      void PrintSequence(int StopNum)      {          int Num;          Num = 1;          while (true)          {              if (Num >= StopNum)                  throw Num;              cout << Num;              Num++;          }      }      int main(void)      {          try          {              PrintSequence(20);          }          catch(int ExNum)          {              cout << "Caught an exception with value: " << ExNum;          }          return 0;      } 

Explanation

The program uses a while loop to print numbers starting from 1 until it reaches the StopNum value. In this case, the StopNum value is 20. The loop will print the numbers 1 to 19, and then when it reaches 20, it will throw an exception with the value 20. The exception is caught in the main function and the message "Caught an exception with value: 20" is printed. Therefore, the output of the program is "prints first 19 numbers and throws exception at 20".

Submit
5. What is the output of this program?      #include <iostream>      using namespace std;      int main()      {          char arr[20];          int i;          for(i = 0; i < 10; i++)              *(arr + i) = 65 + i;          *(arr + i) = '\0';          cout << arr;          return(0);      } 

Explanation

The program declares a character array "arr" with a size of 20. It then uses a for loop to assign values to the elements of the array. The values assigned are characters starting from 65 (ASCII value for 'A') and incrementing by i. After assigning the values, the program adds a null character '\0' to the end of the array to indicate the end of the string. Finally, the program prints the array using cout, which will output "ABCDEFGHIJ".

Submit
6. #include <iostream>      using namespace std;      enum  cat      {          temp = 7      };      int main()      {          int age = 14;          age /= temp;          cout << "If you were cat, you would be " << age << endl;          return 0;      } 

Explanation

The correct answer is "If you were cat, you would be 2" because the code initializes the enum variable "temp" with a value of 7. Then, the code divides the integer variable "age" by the value of "temp" using the /= operator, which performs integer division. Since 14 divided by 7 equals 2, the value of "age" becomes 2. Finally, the code outputs the message "If you were cat, you would be 2" using the cout statement.

Submit
7. #include <iostream>      using namespace std;      long factorial (long a)      {          if (a > 1)              return (a * factorial (a + 1));          else              return (1);      }      int main ()      {          long num = 3;          cout << num << "! = " << factorial ( num );          return 0;      } 

Explanation

The given code is a recursive function that calculates the factorial of a number. However, there is an error in the recursive call of the factorial function. Instead of passing `a + 1` as the argument, it should be `a - 1` in order to calculate the factorial correctly. As a result, when the function is called with the number 3, it goes into an infinite loop and causes a segmentation fault, which is a runtime error.

Submit
8. What is the output of this program? class A     {     int i;     int j;         A()          {             i = 1;             j = 2;         }    }    class Output     {         public static void main(String args[])         {              A obj1 = new A();              A obj2 = new A();          System.out.print(obj1.equals(obj2));         }    }

Explanation

The program creates two objects of class A, obj1 and obj2. The equals() method is called on obj1 with obj2 as the argument. By default, the equals() method in the Object class checks for reference equality, meaning it returns true only if both objects refer to the same memory location. Since obj1 and obj2 are separate objects with different memory locations, the equals() method returns false.

Submit
9. What is the meaning of the following declaration? int(*p[5])();

Explanation

The declaration "int(*p[5])();" means that p is an array of 5 pointers to functions that return an integer. Each element in the array can point to a different function that returns an integer.

Submit
10. What is the output of this program?     class recursion      {         int fact(int n)          {             int result;             if (n == 1)                 return 1;             result = fact(n - 1) * n;             return result;         }     }      class Output      {         public static void main(String args[])          {             recursion obj = new recursion() ;             System.out.print(obj.fact(6));         }     }

Explanation

The program defines a class called "recursion" with a method called "fact" that calculates the factorial of a given number. The method uses recursion to calculate the factorial by calling itself with a smaller value of n until n becomes 1. Then, it returns 1. In the main method of the "Output" class, an object of the "recursion" class is created and the fact method is called with the argument 6. The output of the program is the factorial of 6, which is 720.

Submit
11. Which mechanism is used when a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed? 

Explanation

Inter-thread communication is the mechanism used when a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed. This mechanism allows threads to synchronize their actions and exchange data, ensuring that they do not interfere with each other's execution. It provides a way for threads to communicate and coordinate their activities, enabling them to work together effectively.

Submit
12. Which of these can be overloaded?

Explanation

All of the mentioned options (methods and constructors) can be overloaded. Overloading refers to the ability to have multiple methods or constructors with the same name but different parameters in a class. This allows for more flexibility and versatility in programming, as different versions of the method or constructor can be used depending on the arguments passed. Overloading helps in improving code readability and reusability.

Submit
13. What is Truncation is Java?

Explanation

Truncation in Java refers to the process of converting a floating-point value to an integer type by discarding the decimal part. This means that only the whole number portion of the floating-point value is assigned to the integer type, disregarding any fractional part. This can result in loss of precision, as the decimal part is simply ignored.

Submit
14. What is the output of this program?     import java.util.*;     class Bitset      {         public static void main(String args[])         {             BitSet obj = new BitSet(5);             for (int i = 0; i < 5; ++i)                 obj.set(i);             obj.clear(2);             System.out.print(obj.length() + " " + obj.size());         }     }

Explanation

The program creates a BitSet object with a capacity of 5 bits. It then sets all the bits in the BitSet using a for loop. After that, it clears the bit at index 2. The length() method returns the index of the highest set bit plus one, which is 5 in this case. The size() method returns the size of the BitSet in bits, which is 64. Therefore, the output of the program is "5 64".

Submit
15. #include <stdio.h>      void main()      {          int x = 0;          int *ptr = &5;          printf("%p\n", ptr);      } 

Explanation

The given code will result in a compile time error. This is because the variable "ptr" is a pointer to an integer, and it is being assigned the address of the integer 5. However, assigning a constant value like 5 to a pointer is not allowed in C. Pointers should only be assigned the address of a variable.

Submit
16. What is the type of variable 'b' and 'd' in the below snippet? int a[], b; int []c, d;

Explanation

not-available-via-ai

Submit
17. What is the output of this program?     class recursion      {         int func (int n)          {             int result;             result = func (n - 1);             return result;         }     }      class Output      {         public static void main(String args[])          {             recursion obj = new recursion() ;             System.out.print(obj.func(12));         }     }

Explanation

The program will result in a Run Time Error. This is because the function `func` is recursively calling itself without any base case or termination condition. As a result, the recursion will continue indefinitely, causing a stack overflow error.

Submit
18. An expression in JAVA involving byte, int, and literal numbers is promoted to which of these?

Explanation

In Java, when an expression involves byte, int, and literal numbers, it is promoted to int. This is because int is the default data type for numeric calculations in Java. When byte and int are used together in an expression, the byte value is automatically promoted to int to match the data type of int. Similarly, when literal numbers are involved, they are also treated as int by default. Therefore, the expression is promoted to int.

Submit
19. What is the output of this program? abstract class A      {         int i;         abstract void display();     }         class B extends A      {         int j;         void display()          {             System.out.println(j);         }     }         class Abstract_demo      {         public static void main(String args[])         {             B obj = new B();             obj.j=2;             obj.display();             }     }

Explanation

The program creates an object of class B and assigns a value of 2 to the variable j. Then, the display() method of class B is called, which prints the value of j, which is 2. Therefore, the output of the program is 2.

Submit
20. What is the output of this program?         import java.lang.System;         class Output          {             public static void main(String args[])             {                 byte a[] = { 65, 66, 67, 68, 69, 70 };                 byte b[] = { 71, 72, 73, 74, 75, 76 };                   System.arraycopy(a, 0, b, 3, a.length - 3);                 System.out.print(new String(a) + " " + new String(b));             }         }  

Explanation

The program uses the System.arraycopy() method to copy elements from array a to array b. The method takes the source array (a), the starting index in the source array (0), the destination array (b), the starting index in the destination array (3), and the number of elements to be copied (a.length - 3).

After the arraycopy operation, array a remains unchanged, while elements from array a are copied to array b starting from index 3. Therefore, the output of the program is "ABCDEF GHIABC".

Submit
21. Which of these is a super class of Character wrapper?

Explanation

The super class of the Character wrapper is Number. The Character wrapper class is used to wrap a value of the primitive type char into an object. The Number class, on the other hand, is the abstract superclass of classes that represent numeric values. Since Character is a type of value, it falls under the category of numeric values represented by the Number class. Therefore, Number is the correct answer as it is the super class of the Character wrapper.

Submit
22. . Which of these keywords can be used to prevent inheritance of a class?

Explanation

The keyword "final" can be used to prevent inheritance of a class. When a class is declared as final, it cannot be extended by any other class, thus preventing inheritance. This is useful in situations where the class should not have any subclasses or when the implementation of the class should not be changed or overridden.

Submit
23. What is the output of this program?     #include <cstdlib>     #include <iostream>     using namespace std;     int main()     {         int ran = rand();         cout << ran << endl;     }

Explanation

The output of this program will be a random number between 0 and RAND_MAX. The program uses the rand() function from the cstdlib library to generate a random number and then prints it using the cout statement. The rand() function generates a pseudo-random number between 0 and RAND_MAX, which is a constant defined in the cstdlib library. Therefore, the output can be any number within that range.

Submit
24. . What is the output of the following program? public class Test {     public static void main(String[] args)     {         int value = 3, sum = 6 + -- value         int data = --value + ++value / sum++ * value++ + ++sum  % value--;         System.out.println(data);     } }  

Explanation

The output of the program is 2. The program first assigns the value 3 to the variable "value" and calculates the sum as 6 + (--value), which is 6 + 2 = 8. Then, it calculates the variable "data" using the following expression:
--value + ++value / sum++ * value++ + ++sum % value--;
Since the expressions are evaluated from left to right, the value of "value" becomes 1, "sum" becomes 9, and "data" is calculated as 1 + 2 / 8 * 2 + 10 % 1 = 1 + 0 * 2 + 0 = 1 + 0 + 0 = 1. Finally, the program prints the value of "data" which is 1.

Submit
25. If inner catch handler is not able to handle the exception then__________ .

Explanation

If the inner catch handler is not able to handle the exception, the compiler will check for an appropriate catch handler of the outer try block. This means that the compiler will look for a catch block that can handle the exception in the outer try block. If such a catch block is found, the exception will be handled there. If no appropriate catch handler is found in the outer try block, the program will terminate abnormally.

Submit
26. What is the output of this program?     #include <iostream>     using namespace std;     void fun(int x, int y)     {         x = 20;         y = 10;     }     int main()     {         int x = 10;         fun(x, x);         cout << x;         return 0;     }

Explanation

The program defines a function called 'fun' that takes two integer parameters 'x' and 'y'. Inside the function, the values of 'x' and 'y' are assigned new values of 20 and 10 respectively. However, these changes are local to the function and do not affect the values of 'x' and 'y' in the 'main' function. In the 'main' function, the value of 'x' is initialized as 10 and then the 'fun' function is called with 'x' as both arguments. After the function call, the value of 'x' in the 'main' function remains unchanged. Therefore, when 'x' is printed using 'cout', the output is 10.

Submit
27. State true or false for Java Program. i) Data members of an interface are by default final ii) An abstract class has implementations of all methods defined inside it.

Explanation

In Java, data members of an interface are by default final, meaning they cannot be modified once they are assigned a value. On the other hand, an abstract class does not necessarily have implementations of all the methods defined inside it. It can have both abstract methods, which do not have an implementation, and non-abstract methods, which do have an implementation. Therefore, the correct answer is i-true, ii-false.

Submit
28. Which of the following code retrieves the body of the request as binary data?

Explanation

The correct answer is "DataInputStream data = request.getInputStream()". This code retrieves the body of the request as binary data by using the "getInputStream()" method of the "request" object. The "getInputStream()" method returns an InputStream object that can be used to read the binary data from the request. By assigning it to a DataInputStream object, the binary data can be read in a more convenient way.

Submit
29. What is the output of the following program? public class Test implementsRunnable  {      public void run()      {          System.out.printf("%d",3);      }      public static void main(String[] args) throws Interrupted Exception      {          Thread thread = new Thread(new Test());          thread.start();          System.out.printf("%d",1);          thread.join();          System.out.printf("%d",2);      }     }   

Explanation

The program creates a new thread and starts it. The main thread then prints "1" and waits for the new thread to finish using the join() method. While the main thread is waiting, the new thread prints "3". Once the new thread finishes, the main thread resumes and prints "2". Therefore, the output of the program is "132".

Submit
30. #include <stdio.h>  int main()  {      int* ptr;      *ptr = 5;      printf("%d", *ptr);      return 0;  } 

Explanation

The code is attempting to assign a value of 5 to the memory location pointed to by the uninitialized pointer variable "ptr". This will result in a runtime error because the pointer is not pointing to a valid memory location.

Submit
31. What value will this program return to Java run-time system?      import java.lang.System;         class Output          {             public static void main(String args[])             {                 System.exit(5);             }         }

Explanation

The program will return the value 5 to the Java run-time system because the statement "System.exit(5);" is called in the main method. This statement terminates the currently running Java virtual machine and returns the specified status code, which in this case is 5.

Submit
32. What is the output of this program?   class Output      {         public static void main(String args[])          {                  int a = 1;              int b = 2;              int c = 3;              a |= 4;              b >>= 1;              c <<= 1;              a ^= c;              System.out.println(a + " " + b + " " + c);         }      }

Explanation

The program starts by initializing three variables: a = 1, b = 2, and c = 3.

Then, the program performs several operations on these variables:
- a |= 4: This is a bitwise OR operation, which sets the bits in a to 1 where either a or 4 has a 1 bit. In binary, 4 is represented as 100, so the result of this operation is a = 5.
- b >>= 1: This is a right shift operation, which shifts the bits in b one position to the right. In binary, 2 is represented as 10, so the result of this operation is b = 1.
- c - a ^= c: This is a bitwise XOR operation, which sets the bits in a to 1 where either a or c has a different bit value. In binary, 5 is represented as 101 and 6 is represented as 110, so the result of this operation is a = 3.

Finally, the program prints the values of a, b, and c, which are 3, 1, and 6 respectively.

Submit
33. #include<iostream>  using namespace std;  class Point {      Point() { cout << "Constructor called"; }  };    int main()  {     Point t1;     return 0;  } 

Explanation

The code provided will result in a compiler error. This is because the constructor of the Point class is declared as private and cannot be accessed from outside the class. Therefore, when trying to create an object of the Point class in the main function, a compiler error will occur.

Submit
34. #include<iostream>  using namespace std;  class Point {      Point() { cout << "Constructor called"; }  };    int main()  {     Point t1;     return 0;  } 

Explanation

The given code snippet results in a compiler error because the constructor of the Point class is declared as private. This means that it cannot be accessed from outside the class, including in the main function. As a result, when the code tries to create an instance of the Point class in the main function, it causes a compiler error.

Submit
35. Class Test {      int x;  };  int main()  {    Test t;    cout << t.x;    return 0;  } 

Explanation

The code provided will result in a compiler error. This is because the variable "x" in the Test class is not initialized, and when the program tries to print the value of "t.x", it is accessing an uninitialized variable, which is undefined behavior. To fix this error, the variable "x" should be assigned a value before trying to access it.

Submit
36. What is the error in this code?     byte b = 50;     b = b * 50;

Explanation

The error in this code is that the * operator has converted b * 50 into an int, which cannot be directly assigned to a byte variable without casting. The result of the multiplication exceeds the range of values that can be stored in a byte variable.

Submit
37. Which of the followings is/are automatically added to every class, if we do not write our own. 

Explanation

If we do not write our own, all of the mentioned options (Copy Constructor, Assignment Operator, and a constructor without any parameter) are automatically added to every class. This is because these functions are essential for the proper functioning of a class and are required in many situations. The copy constructor is used to create a new object by copying the values of an existing object. The assignment operator is used to assign the values of one object to another. The constructor without any parameter is used to create objects without any initial values.

Submit
38. How can we connect to database in a web application?

Explanation

JDBC (Java Database Connectivity) is a Java API that allows Java programs to connect to and interact with a database. In a web application, JDBC can be used to establish a connection with a database. The JDBC template is a part of the Spring Framework and provides a higher level of abstraction for database operations. It simplifies the process of database connectivity and allows developers to execute SQL statements and retrieve results from the database. Therefore, using the JDBC template is a valid way to connect to a database in a web application.

Submit
39. #include <iostream>  using namespace std;    class Test  {  public:        Test() { cout << "Hello from Test() "; }  } a;    int main()  {      cout << "Main Started ";      return 0;  } 

Explanation

The given code snippet defines a class called Test with a constructor. It also creates a global object of the Test class named 'a'. In the main function, it first prints "Main Started" and then returns 0.

The correct answer is "Hello from Test() Main Started". This is because when the program starts, the global object 'a' is created and its constructor is called, which prints "Hello from Test()". Then, in the main function, "Main Started" is printed. Therefore, the correct output is "Hello from Test() Main Started".

Submit
40. What is the output of this program?     class bitwise_operator      {         public static void main(String args[])          {                  int a = 3;              int b = 6;           int c = a | b;              int d = a & b;                           System.out.println(c + " "  + d);         }      }

Explanation

The program declares two integer variables, "a" and "b", with values 3 and 6 respectively. It then performs a bitwise OR operation between "a" and "b" and stores the result in variable "c". It also performs a bitwise AND operation between "a" and "b" and stores the result in variable "d". Finally, it prints the values of "c" and "d" separated by a space. The bitwise OR operation combines the binary representation of "a" and "b" by setting each bit to 1 if either bit is 1. In this case, the binary representation of 3 is 0011 and the binary representation of 6 is 0110, so the result of the OR operation is 0111, which is 7 in decimal. The bitwise AND operation combines the binary representation of "a" and "b" by setting each bit to 1 only if both bits are 1. In this case, the result of the AND operation is 0010, which is 2 in decimal. Therefore, the output of the program is "7 2".

Submit
41. What does the following line of code achieve? Intent intent = new Intent(FirstActivity.this, SecondActivity.class );

Explanation

The given line of code creates an explicit Intent that starts an activity. The Intent is used to navigate from the current activity (FirstActivity) to the target activity (SecondActivity). By calling the startActivity() method with this Intent, the SecondActivity is launched and displayed on the screen.

Submit
42. Where is array stored in memory?

Explanation

Arrays in most programming languages are stored in the heap space of the memory. The heap is a region of memory that is used for dynamically allocated memory, which means that the size of the array can be determined at runtime. This allows for flexibility in memory allocation and deallocation. The stack space, on the other hand, is used for storing local variables and function call information. Arrays are not typically stored in the stack space because their size is not fixed and they can be accessed from multiple parts of the program. First generation memory is not a commonly used term in computer science and does not accurately describe where arrays are stored.

Submit
43. Which of these can be returned by the operator & ?

Explanation

The operator '&' in programming is commonly used for bitwise AND operation. It takes two operands and returns an integer or boolean value depending on the context. When used with two integer operands, it performs bitwise AND operation and returns an integer. When used with two boolean operands, it performs logical AND operation and returns a boolean value. Therefore, the correct answer is "Integer or Boolean" as the operator '&' can return either an integer or a boolean value.

Submit
44. Java uses ___ to represent characters

Explanation

Java uses Unicode to represent characters. Unicode is a universal character encoding standard that assigns a unique number to every character, regardless of the platform, program, or language. It provides a consistent way to represent characters from different writing systems and allows Java programs to handle text in multiple languages and scripts. ASCII code, on the other hand, is a character encoding scheme that represents characters using 7 bits and is limited to the English alphabet and a few special characters. Therefore, Unicode is the correct answer in this case.

Submit
45. What does the following code print? System.out.println("13" + 5 + 3);

Explanation

The code concatenates the string "13" with the integer 5, resulting in the string "135". Then, it concatenates the string "135" with the integer 3, resulting in the string "1353". Finally, the code prints the string "1353".

Submit
46. What is the output of this program?      #include <iostream>      using namespace std;      int main()      {          int age = 0;          try          {              if (age < 0)              {                  throw "Positive Number Required";              }              cout << age;          }          catch(const char *Message)          {              cout << "Error: " << Message;          }          return 0;      } 

Explanation

The output of this program is 0. This is because the variable "age" is initialized to 0 at the beginning of the program. Since the condition "age

Submit
47. The order of the three top level elements of the java source file are

Explanation

The correct answer is Package, Import, Class. In a Java source file, the first element is the package declaration, which specifies the package that the class belongs to. The second element is the import statement, which allows the class to use other classes or packages. Finally, the class declaration itself comes last. This order is important as it ensures that the class is properly defined within the correct package and has access to any necessary imports.

Submit
48. Which right shift operator preserves the sign of the value?

Explanation

The right shift operator ">>" preserves the sign of the value. This means that when shifting a negative number to the right, the sign bit (the leftmost bit) is preserved and the vacant bits on the left are filled with copies of the sign bit. Similarly, when shifting a positive number, the sign bit remains 0 and the vacant bits on the left are filled with zeros.

Submit
49. Arrays in Java are implemented as?

Explanation

Arrays in Java are implemented as objects. This means that arrays in Java are instances of a class, specifically the Array class. As objects, arrays have properties and methods that can be used to manipulate and access their elements. This allows for dynamic memory allocation and efficient storage of multiple elements of the same type in a single data structure.

Submit
50. Can we alter/modify the values of data members of a class inside const member function?

Explanation

Yes, we can alter/modify the values of data members of a class inside a const member function. The const keyword in a member function indicates that the function does not modify the object's state, but it does not prevent modifications to the data members themselves. This allows us to make changes to the data members as long as the overall state of the object remains unchanged.

Submit
51. Class Base {   public final void show() {        System.out.println("Base::show() called");     } } class Derived extends Base {     public void show() {          System.out.println("Derived::show() called");     } } public class Main {     public static void main(String[] args) {         Base b = new Derived();;         b.show();     } }

Explanation

The correct answer is 20 because the method show() in the Derived class overrides the show() method in the Base class. When we create an object of the Derived class and assign it to a reference variable of the Base class, the method called will be determined by the type of the reference variable. Since the reference variable b is of type Base, the show() method in the Base class will be called. The show() method in the Derived class is not accessible through the reference variable b.

Submit
52. #include <iostream>  using namespace std;    class Test  {  public:        Test() { cout << "Hello from Test() "; }  } a;    int main()  {      cout << "Main Started ";      return 0;  } 

Explanation

The program creates a global object of the class Test named 'a'. When the program is executed, the main function is called first. It prints "Main Started" and then returns 0. After that, the global object 'a' is initialized and its constructor is called, which prints "Hello from Test()". Therefore, the correct answer is "Hello from Test() Main Started".

Submit
53. What is the output of this program?      #include <iostream>      using namespace std;      int main()      {          float num1 = 1.1;          double num2 = 1.1;          if (num1 == num2)             cout << "stanford";          else             cout << "harvard";          return 0;      } 

Explanation

The program will output "harvard" because the comparison between num1 and num2 will evaluate to false. This is because the float type (num1) and the double type (num2) cannot be compared directly due to their different precision levels. Although the values of num1 and num2 are both 1.1, they are represented slightly differently in memory. Therefore, the else block will be executed and "harvard" will be printed.

Submit
54. What is the difference between servlets and applets? i. Servlets execute on Server; Applets execute on browser ii. Servlets have no GUI; Applet has GUI iii. Servlets creates static web pages; Applets creates dynamic web pages iv. Servlets can handle only a single request; Applet can handle multiple requests

Explanation

Servlets and applets are both components used in web development, but they have some key differences. The first correct statement states that servlets execute on the server, while applets execute on the browser. This is true as servlets are server-side components that process requests and generate responses, while applets are client-side components that run within the browser. The second correct statement mentions that servlets have no GUI (Graphical User Interface), while applets have a GUI. This is also true as servlets are typically used for processing data and generating dynamic content, while applets are used for creating interactive user interfaces within the browser.

Submit
55. #include <stdio.h>  int main()  {      int i = 25;      int* j;      int** k;      j = &i;      k = &j;      printf("%u %u %u ", k, *k, **k);      return 0;  } 

Explanation

The code declares an integer variable `i` and two pointers `j` and `k`. The pointer `j` is assigned the address of `i`, and the pointer `k` is assigned the address of `j`. The `printf` statement prints the address of `k`, the value stored at the address `k` (which is the address of `i`), and the value stored at the address of the address `k` (which is the value of `i`). Therefore, the correct answer is "address address value".

Submit
56. Which of the following statement is correct?

Explanation

The statement is correct because for positive numbers, both the operators ">>" and ">>>" perform right shift operations, but the only difference is that ">>>" is the unsigned right shift operator, which fills the vacant bits with leading zeros, while ">>" is the signed right shift operator, which fills the vacant bits with the sign bit (0 for positive numbers). Therefore, for positive numbers, both operators yield the same result.

Submit
57. What is the output of this program? import java.lang.System;       class Output          {             public static void main(String args[])             {                 byte a[] = { 65, 66, 67, 68, 69, 70 };                 byte b[] = { 71, 72, 73, 74, 75, 76 };                   System.arraycopy(a, 0, b, 0, a.length);                 System.out.print(new String(a) + " " + new String(b));             }         }  

Explanation

The program creates two byte arrays, 'a' and 'b', with the values 65 to 70 and 71 to 76 respectively. It then uses the System.arraycopy() method to copy the elements from array 'a' to array 'b'. Finally, it prints the string representation of array 'a' followed by a space and then the string representation of array 'b'. Therefore, the output of the program is "ABCDEF ABCDEF".

Submit
58. What is the output of below code snippet?    double a = 0.02;    double b = 0.03;    double c = b - a;    System.out.println(c);      BigDecimal _a = new BigDecimal("0.02");    BigDecimal _b = new BigDecimal("0.03");    BigDecimal _c = b.subtract(_a);    System.out.println(_c);

Explanation

The output of the code snippet is 0.009999999999999998 and 0.01.

In the first part of the code, the variables 'a' and 'b' are of type double and the variable 'c' is assigned the value of 'b' minus 'a'. However, due to the nature of floating-point arithmetic, the result is not exactly 0.01 but a slightly imprecise value of 0.009999999999999998.

In the second part of the code, the variables '_a' and '_b' are of type BigDecimal, which is a class that provides arbitrary precision decimal arithmetic. The subtract() method is used to subtract '_a' from '_b', resulting in an exact value of 0.01.

Therefore, the output is 0.009999999999999998 and 0.01.

Submit
59. Which of these interface abstractes the output of messages from httpd?

Explanation

The correct answer is LogMessage because it is the interface that abstracts the output of messages from httpd. This interface is likely responsible for logging and displaying messages related to the functioning of the httpd server.

Submit
60. What is the output of this program? public class Demo {   public static void main(String[] args)   {         Map<Integer, Object> sampleMap = new TreeMap<Integer, Object>();         sampleMap.put(1, null);          sampleMap.put(5, null);          sampleMap.put(3, null);          sampleMap.put(2, null);          sampleMap.put(4, null);           System.out.println(sampleMap);    } }

Explanation

The output of the program is {1=null, 2=null, 3=null, 4=null, 5=null}. This is because the program creates a TreeMap object called sampleMap and inserts null values with keys 1, 5, 3, 2, and 4 in that order. The TreeMap automatically sorts the keys in ascending order, so when the map is printed, it displays the keys in sorted order along with their corresponding null values.

Submit
61. What is the output of the following program? public class Test {     public static void main(String[] args)     {         double data = 444.324;         int value = data;         System.out.println(data);     } }

Explanation

The program will give a compile time error because the variable 'data' is of type double and the variable 'value' is of type int. In Java, you cannot directly assign a value of a larger data type to a variable of a smaller data type without explicit type casting. Since int is a smaller data type than double, the compiler will throw an error.

Submit
62. Which of the following means "The use of an object of one class in definition of another class"? 

Explanation

Composition refers to the use of an object of one class in the definition of another class. It is a way to establish a relationship between classes where one class contains an instance of another class as a member variable. This allows the class to use the functionalities and properties of the contained object. Composition is a form of code reuse and helps to create complex and flexible class structures.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 07, 2019
    Quiz Created by
    Prateek
Cancel
  • All
    All (62)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which option is best to eliminate the memory problem? 
What is the output of this program?  ...
What is the output of this program? ...
What is the output of this program?  ...
What is the output of this program?  ...
#include <iostream>  ...
#include <iostream>  ...
What is the output of this program? ...
What is the meaning of the following declaration? int(*p[5])();
What is the output of this program? ...
Which mechanism is used when a thread is paused running in its...
Which of these can be overloaded?
What is Truncation is Java?
What is the output of this program? ...
#include <stdio.h>  ...
What is the type of variable 'b' and 'd' in the below snippet? ...
What is the output of this program? ...
An expression in JAVA involving byte, int, and literal numbers is...
What is the output of this program? ...
What is the output of this program? ...
Which of these is a super class of Character wrapper?
. Which of these keywords can be used to prevent inheritance of a...
What is the output of this program? ...
. What is the output of the following program? ...
If inner catch handler is not able to handle the exception...
What is the output of this program? ...
State true or false for Java Program. ...
Which of the following code retrieves the body of the request as...
What is the output of the following program? ...
#include <stdio.h>  ...
What value will this program return to Java run-time system? ...
What is the output of this program? ...
#include<iostream>  ...
#include<iostream>  ...
Class Test {  ...
What is the error in this code? ...
Which of the followings is/are automatically added to every class, if...
How can we connect to database in a web application?
#include <iostream>  ...
What is the output of this program? ...
What does the following line of code achieve? ...
Where is array stored in memory?
Which of these can be returned by the operator & ?
Java uses ___ to represent characters
What does the following code print? ...
What is the output of this program?  ...
The order of the three top level elements of the java source file are
Which right shift operator preserves the sign of the value?
Arrays in Java are implemented as?
Can we alter/modify the values of data members of a class inside const...
Class Base { ...
#include <iostream>  ...
What is the output of this program?  ...
What is the difference between servlets and applets? ...
#include <stdio.h>  ...
Which of the following statement is correct?
What is the output of this program? ...
What is the output of below code snippet? ...
Which of these interface abstractes the output of messages from httpd?
What is the output of this program? ...
What is the output of the following program? ...
Which of the following means "The use of an object of one class...
Alert!

Advertisement