Coder's Challenge Group B (Round 1)

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Prateek
P
Prateek
Community Contributor
Quizzes Created: 1 | Total Attempts: 88
Questions: 62 | Attempts: 88

SettingsSettingsSettings
Coders Challenge Group B (Round 1) - Quiz


Questions and Answers
  • 1. 

    How can we connect to database in a web application?

    • A.

      Oracle sql developer

    • B.

      Toad

    • C.

      Mysql

    • D.

      JDBC template

    Correct Answer
    D. JDBC template
    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.

    Rate this question:

  • 2. 

    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;     }

    • A.

      10

    • B.

      20

    • C.

      Compile Time Error

    • D.

      None 

    Correct Answer
    A. 10
    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.

    Rate this question:

  • 3. 

    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);      }     }   

    • A.

      123

    • B.

      213

    • C.

      132

    • D.

      321

    Correct Answer
    C. 132
    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".

    Rate this question:

  • 4. 

    . 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);     } }  

    • A.

      1

    • B.

      2

    • C.

      0

    • D.

      3

    Correct Answer
    B. 2
    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.

    Rate this question:

  • 5. 

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

    • A.

      21

    • B.

      1353

    • C.

      It will give a run-time error

    • D.

      138

    Correct Answer
    B. 1353
    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".

    Rate this question:

  • 6. 

    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.

    • A.

      I-false, ii-false

    • B.

      I-false, ii-true

    • C.

      I-true, ii-false

    • D.

      I-true, ii-true

    Correct Answer
    C. I-true, ii-false
    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.

    Rate this question:

  • 7. 

    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? 

    • A.

      Inter-thread communication

    • B.

      Initial-thread communication

    • C.

      Mutual Exclusive

    • D.

      None of the above

    Correct Answer
    A. Inter-thread communication
    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.

    Rate this question:

  • 8. 

    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);     } }

    • A.

      444.324

    • B.

      444

    • C.

      Compile time error

    • D.

      Run time error

    Correct Answer
    C. Compile time error
    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.

    Rate this question:

  • 9. 

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

    • A.

      Creates an hidden Intent  

    • B.

      Creates an implicit Intent

    • C.

      Create an explicit Intent

    • D.

      Starts an activity.

    Correct Answer
    D. Starts an activity.
    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.

    Rate this question:

  • 10. 

    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();     } }

    • A.

      20

    • B.

      0

    • C.

      Compile time error

    • D.

      Garbage Value

    Correct Answer
    A. 20
    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.

    Rate this question:

  • 11. 

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

    • A.

      Any Number

    • B.

      89

    • C.

      0​ to RAND_MAX

    • D.

      None

    Correct Answer
    C. 0​ to RAND_MAX
    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.

    Rate this question:

  • 12. 

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

    • A.

      P is pointer to function

    • B.

      P is array of pointer to function

    • C.

      P is pointer to such function which return type is the array

    • D.

      P is pointer to array of function

    Correct Answer
    B. P is array of pointer to function
    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.

    Rate this question:

  • 13. 

    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);

    • A.

        0.009999999999999998    0.01

    • B.

      0.01 0.009999999999999998

    • C.

      0.01 0.01

    • D.

      0.009999999999999998 0.009999999999999998

    Correct Answer
    A.   0.009999999999999998    0.01
    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.

    Rate this question:

  • 14. 

    Which of these is a super class of Character wrapper?

    • A.

      Long

    • B.

      Digits

    • C.

      Float

    • D.

      Number

    Correct Answer
    D. Number
    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.

    Rate this question:

  • 15. 

    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);         }      }

    • A.

      7 2

    • B.

      7 7

    • C.

      7 5

    • D.

      5 2

    Correct Answer
    A. 7 2
    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".

    Rate this question:

  • 16. 

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

    • A.

      B cannot contain value 100, limited by its range

    • B.

      * operator has converted b * 50 into int, which can not be converted to byte without casting

    • C.

      B cannot contain value 50

    • D.

      No error in this code

    Correct Answer
    B. * operator has converted b * 50 into int, which can not be converted to byte without casting
    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.

    Rate this question:

  • 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));         }     }

    • A.

      0

    • B.

      1

    • C.

      Compile time error

    • D.

      Run Time Error

    Correct Answer
    D. Run Time Error
    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.

    Rate this question:

  • 18. 

    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));         }     }

    • A.

      1

    • B.

      30

    • C.

      120

    • D.

      720

    Correct Answer
    D. 720
    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.

    Rate this question:

  • 19. 

    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

    • A.

      I,ii,iii are correct

    • B.

      I,ii are correct

    • C.

      I,iii are correct

    • D.

      I,ii,iii,iv are correct

    Correct Answer
    B. I,ii are correct
    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.

    Rate this question:

  • 20. 

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

    • A.

      DataInputStream data = new InputStream()

    • B.

      DataInputStream data = response.getInputStream()

    • C.

      DataInputStream data = request.getInputStream()

    • D.

      DataInputStream data = request.fetchInputStream()

    Correct Answer
    C. DataInputStream data = request.getInputStream()
    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.

    Rate this question:

  • 21. 

    Which of these interface abstractes the output of messages from httpd?

    • A.

      LogMessage

    • B.

      LogResponse

    • C.

      Httpdserver

    • D.

      HttpdResponse

    Correct Answer
    A. LogMessage
    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.

    Rate this question:

  • 22. 

    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");                         }         }     }

    • A.

      12345

    • B.

      123450

    • C.

      1234500

    • D.

      Compilation Error

    Correct Answer
    B. 123450
    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 < 7, which is greater than the length of the array. This causes an ArrayIndexOutOfBoundsException to be thrown. The catch block then prints "0" to the console. Therefore, the output of the program is "123450".

    Rate this question:

  • 23. 

    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);    } }

    • A.

      {1=null, 2=null, 3=null, 4=null, 5=null}

    • B.

      {5=null}

    • C.

      Exception is thrown

    • D.

      {1=null, 5=null, 3=null, 2=null, 4=null}

    Correct Answer
    A. {1=null, 2=null, 3=null, 4=null, 5=null}
    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.

    Rate this question:

  • 24. 

    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());         }     }

    • A.

      4 64

    • B.

      5 64

    • C.

      5 128

    • D.

      4 128

    Correct Answer
    B. 5 64
    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".

    Rate this question:

  • 25. 

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

    • A.

      Compiler Error 

    • B.

      Runtime Error 

    • C.

      Constructor called 

    • D.

      None

    Correct Answer
    A. Compiler Error 
    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.

    Rate this question:

  • 26. 

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

    • A.

      Main Started 

    • B.

      Main Started Hello from Test()

    • C.

      Hello from Test() Main Started

    • D.

      Compiler Error: Global objects are not allowed 

    Correct Answer
    C. Hello from Test() Main Started
    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".

    Rate this question:

  • 27. 

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

    • A.

      0

    • B.

      Garbage Value

    • C.

      Compiler Error

    • D.

      None

    Correct Answer
    C. Compiler Error
    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.

    Rate this question:

  • 28. 

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

    • A.

      Compilation error 

    • B.

      Runtime error 

    • C.

      5

    • D.

      Linker error 

    Correct Answer
    B. Runtime error 
    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.

    Rate this question:

  • 29. 

    #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;  } 

    • A.

      Address address value 

    • B.

      Address value value

    • C.

      Address address address 

    • D.

      Compilation error 

    Correct Answer
    A. Address address value 
    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".

    Rate this question:

  • 30. 

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

    • A.

      5

    • B.

      Address of 5 

    • C.

      Nothing 

    • D.

      Compile time error 

    Correct Answer
    D. Compile time error 
    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.

    Rate this question:

  • 31. 

    Which right shift operator preserves the sign of the value?

    • A.

      <<

    • B.

      >>

    • C.

      <<=

    • D.

      >>=

    Correct Answer
    B. >>
    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.

    Rate this question:

  • 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);         }      }

    • A.

      3 1 6

    • B.

      2 2 3

    • C.

      2 3 4

    • D.

      3 3 6

    Correct Answer
    A. 3 1 6
    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

    Rate this question:

  • 33. 

    What is Truncation is Java?

    • A.

      Floating-point value assigned to an integer type

    • B.

      Integer value assigned to floating type

    • C.

      Floating-point value assigned to an Floating type

    • D.

      Integer value assigned to floating type

    Correct Answer
    A. Floating-point value assigned to an integer type
    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.

    Rate this question:

  • 34. 

    Which of these can be returned by the operator & ?

    • A.

      Integer

    • B.

      Boolean

    • C.

      Character

    • D.

      Integer or Boolean

    Correct Answer
    D. Integer or Boolean
    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.

    Rate this question:

  • 35. 

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

    • A.

      Int

    • B.

      Long

    • C.

      Byte

    • D.

      Float

    Correct Answer
    A. Int
    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.

    Rate this question:

  • 36. 

    Which of these can be overloaded?

    • A.

      Methods

    • B.

      Constructors

    • C.

      All of the mentioned

    • D.

      None of the mentioned

    Correct Answer
    C. All of the mentioned
    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.

    Rate this question:

  • 37. 

    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();             }     }

    • A.

      0

    • B.

      2

    • C.

      Runtime error

    • D.

      Compile time error

    Correct Answer
    B. 2
    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.

    Rate this question:

  • 38. 

    Arrays in Java are implemented as?

    • A.

      Class 

    • B.

      Object

    • C.

      Variable

    • D.

      None

    Correct Answer
    B. Object
    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.

    Rate this question:

  • 39. 

    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));         }    }

    • A.

      False

    • B.

      True

    • C.

      1

    • D.

      Compilation Error

    Correct Answer
    A. False
    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.

    Rate this question:

  • 40. 

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

    • A.

      Super

    • B.

      Constant

    • C.

      Class

    • D.

      Final

    Correct Answer
    D. Final
    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.

    Rate this question:

  • 41. 

    Which option is best to eliminate the memory problem? 

    • A.

      Use smart pointers 

    • B.

      Use raw pointers 

    • C.

      Use virtual destructor 

    • D.

      Use smart pointers & virtual destructor

    Correct Answer
    D. Use smart pointers & virtual destructor
    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.

    Rate this question:

  • 42. 

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

    • A.

      Yes

    • B.

      No

    • C.

      Can't say

    • D.

      None

    Correct Answer
    A. Yes
    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.

    Rate this question:

  • 43. 

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

    • A.

      Compiler will look for outer try handler

    • B.

      Program terminates abnormally

    • C.

      Compiler will check for appropriate catch handler of outer try block

    • D.

      None of these

    Correct Answer
    C. Compiler will check for appropriate catch handler of outer try block
    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.

    Rate this question:

  • 44. 

    Where is array stored in memory?

    • A.

      Heap space

    • B.

      Stack space

    • C.

      Heap space and stack space

    • D.

      First generation memory

    Correct Answer
    A. Heap space
    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.

    Rate this question:

  • 45. 

    What is the type of variable ‘b’ and ‘d’ in the below snippet? int a[], b; int []c, d;

    • A.

      ‘b’ and ‘d’ are int

    • B.

      ‘b’ and ‘d’ are arrays of type int

    • C.

      ‘b’ is int variable; ‘d’ is int array

    • D.

      ‘d’ is int variable; ‘b’ is int array

    Correct Answer
    C. ‘b’ is int variable; ‘d’ is int array
  • 46. 

    Which of the following statement is correct?

    • A.

      For positive numbers, result of operators >> and >>> are same

    • B.

      Java provides two operators to do left shift <<< and <<

    • C.

      >> is the zero fill right shift operator

    • D.

      >>> is the signed right shift operator

    Correct Answer
    A. For positive numbers, result of operators >> and >>> are same
    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.

    Rate this question:

  • 47. 

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

    • A.

      Import, Package, Class

    • B.

      Class, Import, Package

    • C.

      Package, Import, Class

    • D.

      Random order

    Correct Answer
    C. Package, Import, Class
    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.

    Rate this question:

  • 48. 

    Java uses ___ to represent characters

    • A.

      ASCII code

    • B.

      Unicode

    • C.

      Byte code

    • D.

      None

    Correct Answer
    B. Unicode
    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.

    Rate this question:

  • 49. 

    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));             }         }  

    • A.

      ABCDEF    ABCDEF

    • B.

      ABCDEF    GHIJKL

    • C.

      GHIJKL    ABCDEF

    • D.

      GHIJKL     GHIJKL

    Correct Answer
    A. ABCDEF    ABCDEF
    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".

    Rate this question:

  • 50. 

    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));             }         }  

    • A.

      ABCDEF     ABCDEF

    • B.

      ABCDEF     GHIJKL

    • C.

      ABCDEF     GHIABC

    • D.

      GHIJKL     GHIJKL

    Correct Answer
    C. ABCDEF     GHIABC
    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".

    Rate this question:

Quiz Review Timeline +

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.