The document contains questions and answers related to object-oriented programming concepts in Java. Specifically:
1) It discusses core OOP principles like encapsulation, inheritance, polymorphism, and abstraction.
2) It covers object-oriented terminology like class, object, instantiation, constructor.
3) It contains questions on Java concepts like data types, operators, control flow statements and input/output.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
138 views44 pages
MCQ Computer Application by VXL Computer Classes
The document contains questions and answers related to object-oriented programming concepts in Java. Specifically:
1) It discusses core OOP principles like encapsulation, inheritance, polymorphism, and abstraction.
2) It covers object-oriented terminology like class, object, instantiation, constructor.
3) It contains questions on Java concepts like data types, operators, control flow statements and input/output.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44
124 K – BLOCK, KIDWAI NAGAR (in street of Balaji Park and Wedding Bell Banquet hall), Kanpur.
by : Vinod Khare(MCA ,M.Sc., B.Ed.)
phone : 9336061496 1: Which Object-Oriented Programming (OOP) A. The ability of a class to inherit from principle focuses on the ability of a class to multiple classes inherit properties and behaviors from another B. The ability of a method to take on multiple class? forms A. Encapsulation B. Inheritance C. The process of bundling data and methods C. Polymorphism D. Abstraction within a class Answer: B.Inheritance D. The act of creating instances of a class 2: Which OOP principle involves bundling data Answer: B. The ability of a method to take on and methods that operate on that data within multiple forms a single unit? 8: What is the purpose of abstraction in A. Abstraction B. Encapsulation Object-Oriented Programming? C. Polymorphism D. Inheritance A. To hide the internal details of a class and Answer: B. Encapsulation show only what is necessary 3: The principle that allows a class to have B. To create instances of a class multiple methods with the same name, but C. To bundle data and methods within a class with different parameters or types, is known D. To implement multiple forms of a method as: Answer: A. To hide the internal details of a A. Inheritance B. Encapsulation class and show only what is necessary C. Polymorphism D. Abstraction 9:What does the term "instantiation" mean in Answer: C. Polymorphism the context of OOP? 4: In OOP, what is an "object"? A. The process of creating a new class A. A block of code B. A variable B. The act of assigning a value to a variable C. An instance of a classD. A loop construct C. The creation of an instance of a class Answer: C. An instance of a class D. The process of defining a new method 5: What is a "class" in Object-Oriented Answer:C. The creation of an instance of a Programming? class A. A function B. A type of loop 10:In OOP, what is a constructor? C. A blueprint for creating objects A. A method that is called when an object is D. A mathematical equation created Answer: C. A blueprint for creating objects B. A variable that holds the value of an object 6:What does the term "inheritance" refer to in C. A loop construct for creating objects Object-Oriented Programming? D. A type of class A. The ability of a class to inherit properties Answer:A. A method that is called when an from another class object is created B. The act of creating instances of a class 11: What is the purpose of a constructor in a C. The process of hiding the implementation class? details of a class A. To create a new class D. The bundling of data and methods within a B. To instantiate an object class C. To define methods for a class Answer: A. The ability of a class to inherit D. To perform mathematical calculations properties from another class Answer:B. To instantiate an object 7: In OOP, what does the term 12:Which keyword is commonly used to refer "polymorphism" mean? to the current instance of a class in Java? A. this B. super C. class D. object B. bool isTrue = false; Answer:A. this C. boolean flag = "true"; 13:What is the default access modifier for D. bool answer = 1; class members (fields and methods) in Java if Answer:A. boolean status = true; not specified? 21:What is the purpose of the String class in A. private B. protected Java? C. public D. default A. To represent primitive data types Answer:D. default B. To perform mathematical calculations 14:What is the role of access modifiers in a C. To store sequences of characters class? D. To control program flow A. To specify the type of a variable Answer:C. To store sequences of characters B. To control the access level of class members 22:What is the default value for a boolean C. To define mathematical equations variable in Java if it is not explicitly D. To create instances of a class initialized? Answer:B. To control the access level of class A. true B. false C. null D. 0 members Answer:B. false 15:Which of the following is true about static 23:What is the result of the expression 5 > 3 members in a class? && 4 < 7 in Java? A. They are specific to an instance of a class A. true B. false C. 1 D. 0 B. They can be accessed using the class name Answer:A. true C. They cannot be modified 24:Which of the following is the correct syntax D. They are created every time an object is for the ternary conditional operator in Java? instantiated A. x ? a : b B. x ? a, b Answer:B. They can be accessed using the C. x ? a -> b D. x ? a && b class name Answer: 16:Which of the following is not a primitive A. x ? a : b data type in Java? 25:What is the result of the expression A. int B. double C. String D. char 6== 6.0 in Java? Answer:C. String A. true B. false C. 1 D. 0 17:What is the range of values that can be Answer:A. true stored in a byte data type in Java? 26:Which of the following is the correct way to A. -128 to 127 B. 0 to 255 compare two strings for equality in Java? C. -32768 to 32767 A. str1 == str2 B. str1.equals(str2) D. -2147483648 to 2147483647 C. str1.equalsIgnoreCase(str2) Answer:A. -128 to 127 D. Both B and C 18:In Java, which keyword is used to declare Answer:D. Both B and C a constant variable? 27:How can you read an integer input using A. final B. const C. static D. constant the BufferedReader class? Answer:A. final A. nextInt() B. readInt() 19:What is the size of the double data type in C. Integer.parseInt()D. readLine().toInt() Java? Answer:C. Integer.parseInt() A. 4 bytes B. 8 bytes C. 16 bytes 28:Which method is used to read a single D. It varies based on the system character from the user using Answer:B. 8 bytes BufferedReader? 20:Which of the following is a valid declaration A. readChar() B. read() of a boolean variable in Java? C. readCharacter()D. nextChar() A. boolean status = true; Answer:B. read() 29:What is the purpose of the next() method in the Scanner class? A. Reads the next integer A. To exit the entire program B. Reads the next character B. To skip the current iteration of a loop C. Reads the next line of text C. To exit the switch statement and resume D. Reads the next token execution after it Answer:D. Reads the next token D. To print the result to the console 30:What does the Math.floor() method do in Answer:C. To exit the switch statement and Java? resume execution after it A. Returns the smallest integer greater than or 35:What is the purpose of the ternary equal to a number conditional operator (? :) in Java? B. Returns the largest integer less than or A. To declare variables B. To create loops equal to a number C. To assign a value based on a condition C. Rounds a floating-point number to the D. To perform mathematical calculations nearest integer Answer:C. To assign a value based on a D. Returns the square root of a number condition Answer:B. Returns the largest integer less 36:What is the purpose of the default keyword than or equal to a number in a switch statement? 31:What does the Math.random() method A. It represents the default case when none of return in Java? the cases match A. A random boolean value B. It specifies the default value for a variable B. A random integer value C. It indicates the default behavior of a loop C. A random floating-point number between D. It denotes the default visibility of a class 0.0 (inclusive) and 1.0 (exclusive) Answer:A. It represents the default case when D. A random character value none of the cases match Answer:C. A random floating-point number between 0.0 (inclusive) and 1.0 (exclusive) 32:What does the Math.round() method do in Java? A. Rounds a floating-point number to the 37:In Java, which of the following is true nearest integer regarding the switch statement? B. Returns the ceiling of a number A. It can only be used with integers and C. Returns the square root of a number characters D. Calculates the power of a number B. It can only be used with strings Answer:A. Rounds a floating-point number to C. It can be used with any data type the nearest integer D. It can only be used with boolean values 33:What does the Math.randomInt() method Answer:A. It can only be used with integers do in Java? and characters A. Generates a random integer 38:What is the purpose of the continue B. Returns a random floating-point number statement in Java? between 0.0 (inclusive) and 1.0 (exclusive) A. To exit the program C. Finds the maximum of two integers B. To skip the current iteration of a loop and D. Converts a floating-point number to an move to the next one integer C. To terminate the loop immediately Answer:B. Returns a random floating-point D. To jump to a specified label in the code number between 0.0 (inclusive) and 1.0 Answer:B. To skip the current iteration of a (exclusive) loop and move to the next one 34:What is the purpose of the break statement 39:In Java, which loop construct is ideal for in a switch statement? situations where the number of iterations is known? A. while loop B. for loop 46:Which loop construct is most suitable for C. do-while loop D. switch statement scenarios where the loop body needs to be Answer:B. for loop executed at least once? 40:Which loop construct is guaranteed to A. do-while loop B. while loop execute the loop body at least once in Java? C. for loop D. foreach loop A. for loop B. while loop Answer:A. do-while loop C. do-while loop 47:What is the output of the following code D. if statement snippet? Answer: for (int i = 0; i < 5; i++) C. do-while loop { if (i == 3) 41:What is the output of the following code break; snippet? System.out.print(i + " "); } for (int i = 0; i < 5; i++) A. 0 1 2 B. 0 1 2 3 {System.out.print(i + " "); C. 0 1 2 3 4 D. 1 2 3 4 } Answer:A. 0 1 2 A. 0 1 2 3 4 B. 1 2 3 4 5 48:What is the output of the following code C. 0 1 2 3 D. 1 2 3 4 snippet? Answer:A. 0 1 2 3 4 int i = 0; 42:What is the output of the following code do { snippet? System.out.print(i + " "); int x = 0; i += 2; } while (i < 5); do { A. 0 1 2 3 4 B. 0 2 4 6 x++; C. 0 2 4 D. 0 1 3 4 } while (x < 5); Answer:C. 0 2 4 System.out.println(x); 49:In a for loop, what is the purpose of the A. 0 B. 4 C. 5 D. 6 semicolons (;)? Answer:C. 5 A. To separate the initialization, condition, and 43:Which keyword is used to terminate the update statements current iteration of a loop and start the next B. To indicate the end of the loop body one in Java? C. To separate the loop control variable from A. continue B. break C. skip D. next the loop body Answer:A. continue D. To specify the loop termination condition 44:What is the output of the following code Answer:A. To separate the initialization, snippet? condition, and update statements int sum = 0; 50:What is the purpose of the while loop in for (int i = 1; i <= 10; i++) Java? { sum += i;} A. To declare variables System.out.println(sum); B. To specify the condition for loop A. 45 B. 55 C. 50 D. 65 termination Answer:B. 55 C. To execute a block of code repeatedly while 45:What is the output of the following code a condition is true snippet? D. To initialize the loop control variable int x = 5; Answer:C. To execute a block of code while (x > 0) repeatedly while a condition is true { System.out.print(x + " "); 51:In a while loop, what happens if the x--;} condition is initially false? A. 5 4 3 2 1 B. 1 2 3 4 5 A. The loop runs indefinitely C. 5 4 3 2 D. 1 2 3 4 5 6 B. The loop runs once, regardless of the Answer:A. 5 4 3 2 1 condition C. The loop does not execute C. To execute a block of code repeatedly D. The loop executes multiple times D. To define a blueprint for creating objects Answer:C. The loop does not execute Answer: n Java along with their answers: D. To define a blueprint for creating objects 51: In a do-while loop, what happens if the 56:What is the purpose of the this keyword in condition is initially false? Java? A. The loop runs indefinitely A. It refers to the current instance of the class. B. The loop runs once, regardless of the B. It is used to create a new object. condition C. It is a data type in Java. C. The loop does not execute D. It is a reserved keyword for loop constructs. D. The loop executes multiple times Answer:A. It refers to the current instance of Answer:B. The loop runs once, regardless of the class. the condition 57:Which of the following is true about the ination static keyword in Java? 52:Which of the following is true regarding the A. It is used to declare variables. initialization statement in a do-while loop? B. It is used to define methods that belong to A. It is optional the class, rather than instances of the class. B. It is executed after the loop body C. It is used to create objects. C. It is executed before the loop body D. It is used to declare constant values. D. It is not allowed in a do-while loop Answer:B. It is used to define methods that Answer:D. It is not allowed in a do-while loop belong to the class, rather than instances of the class. 58:In Java, what is the purpose of the final keyword? A. It indicates that a class cannot be extended. B. It is used to declare a constant. C. It is used to declare a variable with a fixed value. 53:What is the output of the following code D. It indicates that a method cannot be snippet? overridden. for (int i = 1; i <= 3; i++) Answer:B. It is used to declare a constant. { for (int j = 1; j <= 2; j++) 59:What is the output of the following code { System.out.print(i * j + " "); } snippet? System.out.println(); } class MyClass A.1 2 3 2 4 6 3 6 9 B.1 2 2 4 3 6 { int x; C.2 4 4 8 6 12 D.1 2 3 4 5 6 void setX(int value) Answer:B.1 2 2 4 3 6 { x = value; } 54:In a nested for loop, what does the outer int getX() loop control? { return x; } A. The number of iterations for the inner loop } B. The termination condition for the inner loop public class Main { C. The loop variable for the inner loop public static void main(String[] args) D. The indentation of the inner loop { MyClass obj = new MyClass(); Answer:A. The number of iterations for the obj.setX(42); inner loop System.out.println(obj.getX()); } } 55:What is the purpose of a class in Java? A. 42 B. C. Compilation error A. To declare variables D. "Hello, World!" B. To specify the condition for loop Answer:A. 42 termination 60:What is the purpose of the private access C. It allows access to the class members only modifier in Java? within the same class. A. It allows access to the class or method from D. It is not a valid access modifier in Java. any other class. Answer:B. It allows access to the class B. It restricts access to the class or method to members from any other class. the same package only. 65:In Java, what is the role of the constructor C. It allows access to the class or method from in encapsulation? any class in any package. A. To create objects D. It is not a valid access modifier in Java. B. To initialize the state of an object Answer:B. It restricts access to the class or C. To declare constants method to the same package only. D. To perform mathematical operations 61:Which access modifiers are commonly used Answer:B. To initialize the state of an object to control the visibility of variables and 66:What is an array in Java? methods within a class in Java? A. A primitive data type A. public and protected B. A collection of elements of the same data B. private and default (no modifier) type C. static and final C. A composite data type for decimal numbers D. abstract and final D. A variable that can only hold a single Answer:B. private and default (no modifier) character 62: Answer:B. A collection of elements of the same What does the public access modifier signify data type for a class member (variable or method) in 67:What is the primary difference between Java? primitive data types and reference (composite) A. It can be accessed only within the same data types in Java? class. A. Primitive data types can be assigned null, B. It can be accessed from any other class. while reference data types cannot. C. It can be accessed only within the same B. Primitive data types are always passed by package. reference, while reference data types are D. It cannot be accessed. passed by value. Answer:B. It can be accessed from any other C. Primitive data types store the actual data, class. while reference data types store references to 63:In Java, what is the purpose of the private the data. access modifier for class members? D. Primitive data types can be used in arrays, A. It allows access to the class members from while reference data types cannot. any class. Answer:C. Primitive data types store the actual B. It restricts access to the class members to data, while reference data types store the same package only. references to the data. C. It allows access to the class members only 68:What is a method in Java? within the same class. A. A variable D. It allows access to the class members only B. A class within the same package. C. A function Answer:C. It allows access to the class D. An array members only within the same class. 69.What does the "void" keyword mean in the 64:Which statement is true regarding the method declaration? public access modifier in Java? A. It returns a valueB. It takes no parameters A. It restricts access to the class members to C. It doesn't return any value the same package only. D. It is a data type B. It allows access to the class members from 70.How is a method called in Java? any other class. A. By using the "call" keyword B. By its name followed by parentheses 78. Which keyword is used to declare a C. By using the "method" keyword method in Java? D. By its name followed by square brackets A. method B. define C. function D. void 71. What is the purpose of parameters in a Answer: D. void method? 79. What is the purpose of the "return" A. To define the method statement in a method? B. To specify the return type A. To terminate the program C. To provide input values to the method B. To return a value from the method D. To limit the scope of the method C. To print output 72. Which of the following is a valid method D. To declare a variable declaration in Java? Answer: B. To return a value from the method A. int addNumbers() { } 80. Which of the following is the correct B. void addNumbers(int a, int b) { } syntax for calling a method named C. addNumbers(int a, int b) void { } "calculateSum" with two parameters in Java? D. addNumbers { } A. calculateSum(10, 20); 73. What is the return type of a method that B. calculateSum(int a, int b); doesn't return any value? C. int result = calculateSum(10, 20); A. int B. void C. String D. boolean D. calculateSum = 10 + 20; 74. What is the purpose of the "return" Answer: A. calculateSum(10, 20); statement in a method? 81. What is method overloading in Java? A. To exit the method A. Creating multiple methods with the same B. To specify the return type name but different parameters C. To return a value from the method B. Creating a method inside another method D. To print output to the console C. Using the "overload" keyword in method 75. Can a method have multiple parameters in declaration Java? D. Defining a method with multiple return A. No, only one parameter is allowed types B. Yes, but only if they are of the same data Answer: A. Creating multiple methods with the type same name but different parameters C. Yes, with no restrictions on the number or 82. Which of the following is a valid method data types declaration? D. Yes, but only if they are of different data A. int addNumbers(int a, int b) { return a + b; } types B. void addNumbers(int a, int b) { a + b; } 76. What is method overloading in Java? C. addNumbers(int a, int b) { return a + b; } A. Defining multiple methods with the same D. int addNumbers(int a, int b) => a + b; name but different return types Answer: A. int addNumbers(int a, int b) { B. Defining multiple methods with the same return a + b; } name but different parameter types or number of parameters C. Defining a method inside another method D. Redefining a method in the same class with a different name 83. In Java, can a method be called before it is 77. How is a method defined in Java? declared in the program? A. method name followed by parentheses A. Yes, Java allows forward referencing of B. return type followed by method name methods C. method name followed by parameters B. No, a method must be declared before it is D. method name followed by a semicolon called Answer: B. return type followed by method C. It depends on the method's visibility name D. Only if the method is declared in a different D. Overloading is not applicable to class constructors Answer: B. No, a method must be declared Answer: C. Yes, constructors can be before it is called overloaded in the same way as methods 84. Which of the following must be different to 90. In method overloading, can methods have overload a method in Java? different access modifiers? A. Method name B. Return type A. Yes, any combination of access modifiers is C. Parameters D. Access modifier allowed. Answer: C. Parameters B. No, methods must have the same access 85. Can method overloading be based solely modifier. on the return type of the method? C. Only public access modifier is allowed. A. Yes B. No C. Sometimes D. It depends on the return type. D. Only for static methods Answer: A. Yes, any combination of access Answer: B. No modifiers is allowed. 86. Which of the following is a valid example 91. What is the correct syntax for declaring a of method overloading? method in Java? A. int addNumbers(int a, int b) { return a + b; } A. method returnType B. double addNumbers(int x, int y) { return x + methodName(parameters) {} y; } B. returnType methodName(parameters) {} C. int addNumbers(int a, int b, int c) { return a C. methodName(parameters) returnType {} + b + c; } D. methodName {} returnType(parameters); D. All of the above Answer: B. returnType Answer: D. All of the above methodName(parameters) {} 87. What is the role of the compiler in 92. What is the purpose of the return type in a resolving overloaded methods? method declaration? A. Compiler chooses the method with the A. It specifies the type of the method. highest visibility B. It specifies the type of the parameters. B. Compiler chooses the method with the C. It indicates whether the method is public or highest return type private. C. Compiler selects the method with the most D. It specifies the type of value the method will parameters return. D. Compiler determines the correct method Answer: D. It specifies the type of value the based on the method signature method will return. Answer: D. Compiler determines the correct 93. Which of the following is a valid method method based on the method signature declaration for a method named "display" that 88.Which of the following is not a valid way to does not take any parameters and returns a overload a method? double in Java? A. Changing the order of parameters A. double display() {} B. Changing the return type B. display(double): {} C. Changing the access modifier C. void display(double) {} D. Changing the number of parameters D. display() => double {} Answer: B. Changing the return type Answer: A. double display() {} 89. Can constructors be overloaded in Java? 94. In a method declaration, what does the A. No, constructors cannot be overloaded access modifier specify? B. Yes, but only if they have different return A. The return type of the method. types B. The visibility or accessibility of the method. C. Yes, constructors can be overloaded in the C. The number of parameters the method can same way as methods accept. D. The name of the method. Answer: B. The visibility or accessibility of the Answer: C. Changes made inside the method method. do not affect original values. 95. What is Call by Value in Java? 101. Which of the following is an example of A. The actual value of the argument is passed Call by Value in Java? to the method. A. void processString(String str) {} B. The memory address of the argument is B. void calculateAverage(double[] values) {} passed to the method. C. int incrementValue(int num) {} C. A reference to the argument is passed to D. All of the above the method. Answer: D. All of the above D. The type of the argument is passed to the 102. What is the role of actual parameters in a method. method call in Java? Answer: A. The actual value of the argument is A. They define the method's return type. passed to the method. B. They specify the method's visibility. 96. Which data types are passed by value in C. They provide values to the method's Java? parameters. A. Objects B. Arrays C. Primitive data D. They declare the method's name. types D. Strings Answer: C. They provide values to the Answer: C. Primitive data types method's parameters. 97. If you pass a primitive data type to a 103. Which of the following represents actual method and modify its value inside the parameters in a method call? method, does it affect the original value A. The parameters listed in the method outside the method? declaration. A. Yes B. No B. The values passed to a method during its C. It depends on the method's access modifier invocation. D. Only if the method is declared as static C. The return type of the method. Answer: B. No D. The method name. 98. Consider the following method declaration: Answer: B. The values passed to a method void updateValue(int x) during its invocation. { x = x * 2; } 104.In the method call calculateSum(10, 20);, If you call updateValue(5);, what will be the what are the actual parameters? value of x after the method call? A. 10 and 20 B. calculateSum A. 5 B. 10 C. 15 D. 20 C. The method declaration Answer: A. 5 D. The return type of the method 99. In Call by Value, can changes made to the Answer: A. 10 and 20 parameter inside the method affect the original 105.What is the primary purpose of formal value outside the method? parameters in a method declaration? A. Yes B. No A. They provide values to the method during C. It depends on the method's visibility invocation. D. Only if the method is declared as static B. They specify the method's visibility. Answer: B. No C. They declare the method's return type. 100. Which of the following is a characteristic D. They act as placeholders for values that will of Call by Value? be passed during method invocation. A. Original values are always modified. Answer: D. They act as placeholders for values B. Memory addresses are passed to the that will be passed during method invocation. method. 106.Which of the following is an example of C. Changes made inside the method do not formal parameters in a method declaration? affect original values. A. void process(int x, int y) {} D. It is the default parameter passing B. process(10, 20); mechanism in Java. C. calculateSum = 10 + 20; D. int result = process(5, 3); Answer: A. void process(int x, int y) {} 107. In the method declaration void displayInfo(String name, int age) {}, what are 111. In a static method, can you access non- the formal parameters? static (instance) variables directly? A. void, displayInfo, String, int A. Yes, always B. name, age B. No, never C. String name, int age C. Only if they are declared as final D. displayInfo(String name, int age) D. Only if the method is declared as public Answer: C. String name, int age Answer: B. No, never 108.What happens if the number of actual 112. If a method is declared as static, can it parameters in a method call does not match access other static methods directly without the number of formal parameters in the creating an object? method declaration? A. Yes, always A. It is not allowed in Java. B. No, never B. Java automatically adds or removes C. Only if the methods have the same return parameters as needed. type C. The method call will result in a compilation D. Only if the methods have the same visibility error. Answer: A. Yes, always D. The extra parameters are ignored. 113. Which of the following statements is true Answer: C. The method call will result in a about static methods in Java? compilation error. A. Static methods can access only static 109. Which of the following is true about the variables. scope of formal parameters? B. Static methods can only be called from A. Formal parameters are only visible inside within the same class. the method. C. Static methods cannot have a return type. B. Formal parameters are visible throughout D. Static methods can be called using the the entire program. class name. C. Formal parameters are global variables. Answer: D. Static methods can be called using D. Formal parameters have the same scope as the class name. instance variables. 114. What is a static variable in Java? Answer: A. Formal parameters are only visible A. A variable that can only be accessed within inside the method. the same class. 110. What is the main difference between a B. A variable that belongs to a specific static method and a non-static (instance) instance of a class. method in Java? C. A variable that is shared among all A. Static methods can only be called within instances of a class. the same class. D. A variable declared with the final keyword. B. Non-static methods can be called without Answer: C. A variable that is shared among all creating an instance of the class. instances of a class. C. Static methods can access only static 115.In a non-static (instance) method, can variables. you directly access static variables of the D. Non-static methods require the creation of class? an object to be called. A. Yes, always B. No, never Answer: D. Non-static methods require the C. Only if the static variables are declared as creation of an object to be called. public D. Only if the method is declared as private Answer: A. Yes, always 116. What is the scope of a non-static will return. (instance) variable in Java? D. It is optional in a method signature. A. It is local to the method in which it is Answer: C. It indicates the type of value the declared. method will return. B. It is visible throughout the entire program. 122.Which of the following is a valid method C. It is limited to the class in which it is prototype in Java? declared. A. int calculateSum(int x, int y); D. It can only be accessed by other classes in B. calculateSum(int x, int y): int; the same package. C. void calculateSum(int x, int y) => x + y; Answer: C It is limited to the class in which it D. calculateSum => int {int x, int y}; is declared. Answer: A. int calculateSum(int x, int y); 117. Can a static variable be accessed without 123. Which of the following statements is true creating an instance of the class? about method overloading in Java? A. Yes, always B. No, never A. Methods must have the same return type to C. Only if the static variable is declared asbe overloaded. final B. Methods must have the same number of D. Only if the class is declared as public parameters to be overloaded. Answer: A. Yes, always C. Methods must have the same name and 118. In a static method, can you access a parameter types (in the same order) to be non-static (instance) variable directly? overloaded. A. Yes, always B. No, never D. Overloading is not allowed in Java. C. Only if the variable is declared as final Answer: C. Methods must have the same D. Only if the method is declared as public name and parameter types (in the same order) Answer: B. No, never to be overloaded. 119. What is a method prototype in Java? 124. What information is essential in a A. The definition of a method. method prototype? B. The declaration of a method. A. Method name and return type. C. The return type of a method. B. Return type and parameter names. D. The body of a method. C. Method name and method body. Answer: B. The declaration of a method. D. Access modifier and parameter types. Answer: A. Method name and return type. 125.If a method is declared with the same name, return type, and parameter types as another method in the same class, what is the 120. What does a method signature consist of result? in Java? A. It results in a compilation error. A. The method name only. B. It is allowed, and the methods are B. The return type and the method name. considered overloaded. C. The return type, method name, and C. It is allowed, and the methods are parameter types (if any). considered overridden. D. The method name and the number of D. It depends on the order in which the parameters. methods are declared. Answer: C. The return type, method name, Answer: A. It results in a compilation error. and parameter types (if any). 126. What is a pure method in Java? 121.In a method signature, what is the A. A method that returns a value and has no purpose of the return type? side effects. A. It specifies the method's visibility. B. A method that modifies global variables. B. It defines the method's name. C. A method that throws exceptions. C. It indicates the type of value the method D. A method that is declared as static. Answer: A. A method that returns a value and B. Yes, but only if they are within a loop. has no side effects. C. No, only one return statement is allowed. 127. Which of the following is a characteristic D. Yes, as long as they are in different of pure methods? branches of a conditional statement. A. They can modify global variables. Answer: D. Yes, as long as they are in different B. They may have side effects. branches of a conditional statement. C. Their output solely depends on their input 133.Which of the following is true about the parameters. order of statements in a method with a return D. They require the use of the synchronized statement? keyword. A. The return statement must always be the Answer: C. Their output solely depends on first statement. their input parameters. B. The return statement must always be the 128. What is an impure method in Java? last statement. A. A method that returns a value and has no C. The return statement can be placed side effects. anywhere in the method. B. A method that modifies global variables. D. The return statement is not allowed in C. A method that does not throw exceptions. methods. D. A method declared with the final keyword. Answer: B. The return statement must always Answer: B. A method that modifies global be the last statement. variables. 134. In Java, can a method with a void return 129. What is the primary disadvantage of type include a return statement? impure methods in Java? A. Yes, but only if the return statement does A. They cannot be declared as static. not specify a value. B. They can have unexpected side effects. B. Yes, as long as the method has a single C. They are slower than pure methods. return statement. D. They require the use of the volatile C. No, void methods cannot have a return keyword. statement. Answer: B. They can have unexpected side D. Yes, as long as the method has a effects. conditional return statement. 130. What is the purpose of the return Answer: A. Yes, but only if the return statement in a Java method? statement does not specify a value. A. To terminate the program. 135. What is the purpose of returning a value B. To declare the method's return type. from a method in Java? C. To return a value from the method. A. It is mandatory for all methods. D. To skip the remaining code in the method. B. It allows the method to be called from other Answer: C. To return a value from the method. classes. 131. In Java, what does a method with a void C. It enables the method to produce a result return type indicate? that can be used by the caller. A. The method does not return any value. D. It is a way to declare the method's return B. The method returns an integer. type. C. The method returns a boolean value. Answer: C. It enables the method to produce a D. The method is not allowed to have a return result that can be used by the caller. statement. Constructors in Java: Answer: A. The method does not return any 136. How is a constructor different from a value. regular method in Java? 132.In Java, can a method have multiple A. Constructors have a return type, while return statements? methods do not. A. Yes, but only if they return the same data B. Constructors cannot be called explicitly, type. while methods can. C. Constructors are used to initialize objects, modifiers. while methods perform operations. D. No, all constructors must be public. D. Constructors can be private, while methods Answer: B. Yes, but it cannot be called from cannot. outside the class. Answer: C. Constructors are used to initialize 142. Which type of constructor is objects, while methods perform operations. automatically created by the compiler if no 137. Can a class have multiple constructors constructor is defined in a class? in Java? A. Default constructor A. No, only one constructor is allowed. B. Parameterized constructor B. Yes, but they must have different names. C. Private constructor C. Yes, but they must have the same D. Static constructor parameter types. Answer: A. Default constructor D. Yes, through constructor overloading. 143. What is the primary purpose of a Answer: D. Yes, through constructor parameterized constructor in Java? overloading. A. To initialize instance variables with default 138. Which of the following is true about the values. default constructor in Java? B. To create an object of the class without A. It must be explicitly defined in the class. providing any initial values. B. It has parameters provided by the C. To accept parameters and initialize instance programmer. variables with specific values. C. It is automatically created by the compiler if D. To prevent the creation of objects of the no constructor is defined. class. D. It cannot be used to initialize instance Answer: C. To accept parameters and initialize variables. instance variables with specific values. Answer: C. It is automatically created by the compiler if no constructor is defined. 139. Which of the following statements about constructors is false? A. Constructors cannot be overloaded. 144. Can a class have both a no-argument B. Constructors can have access modifiers. constructor and a parameterized constructor? C. Constructors can have parameters. A. Yes, but only if the class is abstract. D. Constructors are called when an object is B. Yes, as long as the no-argument created. constructor is declared as private. Answer: A. Constructors cannot be C. No, it is not allowed. overloaded. D. Yes, through constructor overloading. 140. Can a constructor have a return type? Answer: D. Yes, through constructor A. Yes, but it must be void. overloading. B. Yes, any valid data type. 145. When is a constructor called in Java? C. No, constructors cannot have a return type. A. When an object is created. D. No, constructors must return an object of B. When a method is invoked. the class. C. When a variable is declared. Answer: C. No, constructors cannot have a D. When an object is destroyed. return type. Answer: A. When an object is created. 141.Can a constructor be private in Java? 146. What is constructor overloading in Java? A. Yes, but only if the class has no other A. Using multiple constructors with the same constructors. name and parameters in a class. B. Yes, but it cannot be called from outside B. Using different names for constructors in a the class. class. C. No, constructors cannot have access C. Declaring constructors with different return types. A. It can have parameters. D. Creating constructors with different access B. It can be explicitly defined in the class. modifiers. C. It initializes instance variables with default Answer: A. Using multiple constructors with values. the same name and parameters in a class. D. It is invoked only when the this() 147. Can the return type of a constructor be constructor call is used. used for constructor overloading? Answer: C. It initializes instance variables with A. Yes, different return types can be used. default values. B. No, the return type does not participate in 148. What is the access modifier of a default constructor overloading. constructor in Java? C. Yes, as long as the return type is explicitly A. public specified. B. private D. No, constructor return types must be the C. protected same. D. No access modifier is specified. Answer: B. No, the return type does not Answer: D. No access modifier is specified. participate in constructor overloading. 149. Which of the following statements is true 148.How does Java differentiate between about the default constructor? overloaded constructors during a method call? A. It must be explicitly defined in every class. A. By the number of parameters. B. It can be explicitly defined with parameters. B. By the order of parameters. C. It is always invoked when an object is C. By the return type. created. D. By the access modifiers. D. It cannot initialize instance variables. Answer: A. By the number of parameters. Answer: C. It is always invoked when an object 145. Which of the following statements about is created. constructor overloading is false? 150. What is the primary purpose of a A. Constructors in the same class must have parameterized constructor? the same number of parameters. A. To create an object without providing any B. Constructors in the same class must have initial values. the same data types for parameters. B. To provide a default implementation for the C. Constructors in the same class can have class. different access modifiers. C. To initialize instance variables with specific D. Constructors in the same class can have values passed as parameters. different names. D. To create a constructor with multiple Answer: D. Constructors in the same class can access modifiers. have different names. Answer: C. To initialize instance variables with 146. What is a default constructor in Java? specific values passed as parameters. A. A constructor with no parameters. 151. Can a class have both a parameterized B. A constructor with a default constructor and a default constructor? implementation. A. No, it is not allowed. C. A constructor that is automatically created B. Yes, but the default constructor must be by the compiler if no constructor is defined. declared as private. D. A constructor that initializes all variables to C. Yes, through constructor overloading. default values. D. Yes, but the parameterized constructor Answer: C. A constructor that is automatically must be declared as private. created by the compiler if no constructor is Answer: C. Yes, through constructor defined. overloading. 147. Which of the following is true regarding 152. Which of the following statements about the default constructor in Java? parameterized constructors is true? A. Parameterized constructors cannot be C. To create a new wrapper object with a overloaded. specified value. B. Parameterized constructors must always D. To compare two wrapper objects. have a return statement. Answer: C. To create a new wrapper object C. Parameterized constructors can have with a specified value. different access modifiers. 158. Which of the following is an example of D. Parameterized constructors cannot be autoboxing? invoked explicitly. A. int num = Integer.parseInt("123"); Answer: C. Parameterized constructors can B. Integer intValue = 42; have different access modifiers. C. String str = Integer.toString(123); t access modifiers. D. double doubleValue = Wrapper Classes in Java: Double.valueOf("3.14"); 153. What is the purpose of wrapper classes Answer: B. Integer intValue = 42; in Java? 159. What is unboxing in Java? A. To provide a convenient way to create A. Converting primitive types to their objects. corresponding wrapper classes automatically. B. To convert primitive data types into objects B. Converting wrapper classes to primitive and vice versa. types automatically. C. To wrap multiple classes together. C. Wrapping multiple classes together. D. To enhance the security of the code. D. Converting objects to primitive data types. Answer: B. To convert primitive data types into Answer: B. Converting wrapper classes to objects and vice versa. primitive types automatically. 154. Which of the following is a wrapper class 160. Which of the following is an example of for the primitive data type int? unboxing? A. Integer B. Int A. Integer intValue = new Integer(42); C. intWrapper D. IntegerWrapper B. int num = Integer.valueOf("123"); Answer: A. Integer C. double doubleValue = 155. Which of the following methods is used Double.parseDouble("3.14"); to convert a String to an integer using the D. int num = intValue; Integer wrapper class? Answer: D. int num = intValue; A. parseInt() B. convertToInt() 161.Which of the following is a benefit of C. toInteger() D. castToInt() autoboxing and unboxing? Answer: A. parseInt() A. It increases the complexity of the code. 156. What is autoboxing in Java? B. It reduces the need for explicit casting. A. Converting objects to primitive data types. C. It only works with a subset of primitive B. Converting primitive data types to their types. corresponding wrapper classes automatically. D. It is recommended only for advanced users. C. Wrapping multiple classes together. Answer: B. It reduces the need for explicit D. Converting wrapper classes to primitive casting. data types. 162. What is a composite type in Java? Answer: B. Converting primitive data types to A. A class that cannot be instantiated. their corresponding wrapper classes B. A class that contains references to other automatically. objects. 157. What is the purpose of the valueOf() C. A primitive data type. method in wrapper classes? D. A class that cannot have methods. A. To obtain the primitive value from the Answer: B. A class that contains references to wrapper object. other objects. B. To convert a primitive value to a wrapper object. A. To enhance security in the code. B. To simplify the process of converting between primitive types and their corresponding wrapper classes. 163.. Which of the following Java keywords is C. To reduce the need for object-oriented used to create an instance of a composite type programming. (object)? D. To make the code more complex. A. class B. new Answer: B. To simplify the process of C. instanceof D. create converting between primitive types and their Answer: B. new corresponding wrapper classes. 164. In a composite type, what is the purpose 169. In the following code, what will be the of encapsulation? value of result? A. To prevent the creation of objects. String numStr = "456"; B. To hide the implementation details of the int result = Integer.parseInt(numStr); class. A. 456 B. 0 C. -1 C. To limit the number of methods in the D. NumberFormatException class. Answer: A. 456 D. To enforce strict data type rules. 170. What is the purpose of the isDigit(char Answer: B. To hide the implementation details ch) method in Java? of the class. A. To check if a character is a digit. 165. Which of the following is an example of B. To convert a character to a digit. using a class as a composite type? C. To check if a character is alphabetic. A. int num = 42; D. To check if a character is a special B. double value = 3.14; character. C. String name = "John"; Answer: A. To check if a character is a digit. D. Person person = new Person(); 171. Which of the following statements is true Answer: D. Person person = new Person(); about the isDigit(char ch) method? 166.. What is the purpose of the A. It returns true for any character. parseInt(String s) method in Java? B. It only accepts uppercase characters. A. To convert a string to a double value. C. It considers both uppercase and lowercase B. To convert a string to an integer value. digits. C. To parse an object into a string D. It is not a valid method in Java. representation. Answer: C. It considers both uppercase and D. To obtain the length of a string. lowercase digits. Answer: B. To convert a string to an integer 172. In the code snippet below, what will be value. the value of result? 167. What happens if the string passed to char ch = '7'; parseInt(String s) contains non-numeric boolean result = Character.isDigit(ch); characters? A. true B. false C. '7' D. 'false' A. The method returns 0. Answer: A. true B. The method returns -1. 173. Which of the following characters would C. The method throws a return false when passed to isDigit(char ch)? NumberFormatException. A. '3' B. 'C' C. '%' D. '$' D. The method automatically converts the Answer: C. '%' characters to their ASCII values. 174.. What is the purpose of the isLetter(char Answer: C. The method throws a ch) method in Java? NumberFormatException. A. To check if a character is a digit. 168. What is the purpose of autoboxing and B. To check if a character is alphabetic. unboxing in Java? C. To check if a character is a special character. C. To convert a character to uppercase. D. To convert a character to uppercase. D. To check if a character is a digit. Answer: B. To check if a character is Answer: A. To check if a character is an alphabetic. uppercase letter. 175.2. Which of the following characters 182. Which of the following characters would would return true when passed to return true when passed to isUpperCase(char isLetter(char ch)? ch)? A. 'A' B. '5' C. '%' D. '$' A. 'A' B. 'z' C. '3' D. '$' Answer: A. 'A' Answer: A. 'A' 176. What is the purpose of the 183. What does the isUpperCase(char ch) isLetterOrDigit(char ch) method in Java? method return for a non-alphabetic character? A. To check if a character is alphabetic. A. true B. false C. -1 B. To check if a character is a digit. D. NumberFormatException C. To check if a character is a special Answer: B. false character. 184.What is the purpose of the D. To check if a character is either a letter or a isWhitespace(char ch) method in Java? digit. A. To check if a character is an uppercase Answer: D. To check if a character is either a letter. letter or a digit. B. To check if a character is a digit. 177. Which of the following characters would C. To check if a character is a whitespace return true when passed to character. isLetterOrDigit(char ch)? D. To convert a character to lowercase. A. 'A' B. '5' C. '%' D. '$' Answer: C. To check if a character is a Answer: A. 'A' whitespace character. 178. What is the purpose of the 184.2. Which of the following characters isLowerCase(char ch) method in Java? would return true when passed to A. To check if a character is an uppercase isWhitespace(char ch)? letter. A. ' ' (space) B. '\n' (newline) B. To check if a character is a lowercase letter. C. 'A' D. '5' C. To convert a character to lowercase. Answer: A. ' ' (space) and B. '\n' (newline) D. To check if a character is a digit. 185.3. What does the isWhitespace(char ch) Answer: B. To check if a character is a method return for a non-whitespace lowercase letter. character? 179.2. Which of the following characters A. true B. false C. -1 would return true when passed to D. NumberFormatException isLowerCase(char ch)? Answer: B. false A. 'A' B. 'z' C. '3' D. '$' 186. What is the purpose of the Answer: B. 'z' toLowerCase(char ch) method in Java? 180. What does the isLowerCase(char ch) A. To check if a character is an uppercase method return for a non-alphabetic character? letter. A. true B. false C. -1 B. To convert a character to lowercase. D. NumberFormatException C. To check if a character is a digit. Answer: B. false D. To check if a character is a whitespace 181. What is the purpose of the character. isUpperCase(char ch) method in Java? Answer: B. To convert a character to A. To check if a character is an uppercase lowercase. letter. 187. Which of the following characters would B. To check if a character is a lowercase letter. return a lowercase equivalent when passed to toLowerCase(char ch)? A. 'A' B. 'z' C. '3' D. '$' A. public B. private C. protected Answer: A. 'A' D. default 188. What does the toLowerCase(char ch) Answer: D. default method return for a non-alphabetic character? 195. In Java, what does the private access A. true B. The original character specifier mean? C. -1 D. NumberFormatException A. Accessible within the same class only. Answer: B. The original character B. Accessible within the same package. 189. Which of the following statements is true C. Accessible by any class in any package. about the toLowerCase(char ch) method? D. Accessible by subclasses. A. It returns true for any character. Answer: A. Accessible within the same class B. It only accepts uppercase characters. only. C. It converts both uppercase and lowercase 196. What is the scope of the protected access letters. specifier in Java? D. It is not a valid method in Java. A. Accessible within the same class only. Answer: C. It converts both uppercase and B. Accessible within the same package. lowercase letters. C. Accessible by any class in any package. 190. What is the purpose of the D. Accessible by subclasses and classes in the toUpperCase(char ch) method in Java? same package. A. To check if a character is an uppercase Answer: D. Accessible by subclasses and letter. classes in the same package. B. To convert a character to uppercase. 197. Which access specifier provides the C. To check if a character is a digit. widest scope in Java? D. To check if a character is a whitespace A. public B. private C. protected character. D. default Answer: B. To convert a character to Answer: A. public uppercase. 198. In Java, which of the following access 191. Which of the following characters would specifiers is not allowed for top-level classes? return an uppercase equivalent when passed A. public to toUpperCase(char ch)? B. private A. 'a' B. 'Z' C. '3' D. '$' C. protected Answer: A. 'a' D. default 192.1. What are the access specifiers in Java Answer: B. private used for? 199.What happens if an attempt is made to A. Specifying the data type of a variable. access a private member from a different class B. Controlling the access level of classes, in Java? fields, and methods. A. Compilation error. B. Runtime exception. C. Defining the return type of a method. C. The access is allowed. D. Allocating memory for objects. D. A warning is issued. Answer: B. Controlling the access level of Answer: A. Compilation error. classes, fields, and methods. 9. Which of the following is a valid declaration 193. Which of the following is not an access of a private field in a Java class? specifier in Java? A. private int count; A. public B. private C. protected B. public private count; D. static C. private static int count; Answer: D. static D. protected int count; 194. What is the default access level for Answer: A. private int count; members (fields and methods) of a class if no access specifier is specified? D. Global, accessible in any class in any package. Answer: A. Limited to the method or block in which it is declared. 200. What is the significance of the private 205. What is the scope of a variable declared access specifier in terms of class within a loop or conditional statement in encapsulation in Java? Java? A. It breaks encapsulation by allowing external A. Limited to the loop or conditional classes to access private members. statement. B. It enforces encapsulation by restricting B. Accessible throughout the entire class. access to class internals. C. Accessible in any class within the same C. It has no impact on encapsulation. package. D. It makes all class members public. D. Global, accessible in any class in any Answer: B. It enforces encapsulation by package. restricting access to class internals. Answer: A. Limited to the loop or conditional 201. What is the primary purpose of the statement. protected access specifier in Java? 206. What is the scope of a variable declared A. Accessible within the same class only. as final in Java? B. Accessible within the same package. A. Limited to the method or block in which it C. Accessible by any class in any package. is declared. D. Accessible by subclasses and classes in the B. Accessible throughout the entire class. same package. C. Accessible in any class within the same Answer: D. Accessible by subclasses and package. classes in the same package. D. Global, accessible in any class in any 202. What is the scope of a local variable in package. Java? Answer: A. Limited to the method or block in A. Limited to the method or block in which it which it is declared. is declared. 208. In Java, what happens if you attempt to B. Accessible throughout the entire class. access a variable outside its scope? C. Accessible in any class within the same A. It results in a compilation error. package. B. It results in a runtime error. D. Global, accessible in any class in any C. The variable becomes global. package. D. The variable becomes inaccessible. Answer: A. Limited to the method or block in Answer: A. It results in a compilation error. which it is declared. 209. What is a class variable in Java? 203. Which type of variable has the narrowest A. A variable declared inside a method. scope in Java? B. A variable declared with the static keyword A. Local variable within a class. B. Instance variable C. A variable declared as final within a class. C. Class (static) variable D. A variable declared with the public access D. Final variable specifier. Answer: A. Local variable Answer: B. A variable declared with the static 204.5. In Java, what is the scope of a keyword within a class. parameter passed to a method? 210. How is a class variable different from an A. Limited to the method or block in which it instance variable in Java? is declared. A. Class variables are initialized using the new B. Accessible throughout the entire class. keyword. C. Accessible in any class within the same B. Instance variables are declared with the package. static keyword. C. Class variables have only one copy shared Answer: D. A variable declared without the among all instances of the class. static keyword within a class. D. Instance variables are accessed using the 216. How is an instance variable different class name. from a class variable in Java? Answer: C. Class variables have only one copy A. Instance variables are declared with the shared among all instances of the class. static keyword. 211. Which of the following statements is true B. Class variables are initialized using the new about the initialization of class variables in keyword. Java? C. Instance variables have only one copy A. Class variables must be initialized when shared among all instances of the class. declared. D. Class variables are accessed using the class B. Class variables are automatically initialized name. to their default values. Answer: C. Instance variables have only one C. Class variables can only be initialized copy for each instance of the class. within a constructor. 217.. How is an instance variable specific to D. Class variables cannot be initialized. each object in Java? Answer: B. Class variables are automatically A. By declaring it as public. initialized to their default values. B. By declaring it as final. 212. In Java, what happens if a class variable C. By declaring it with the static keyword. is modified in one instance of a class? D. By not declaring it with the static keyword. A. It only affects that specific instance. Answer: D. By not declaring it with the static B. It affects all instances of the class. keyword. C. It results in a compilation error. 218.7. In Java, what happens if an instance D. It requires synchronization to be modified. variable is modified in one instance of a class? Answer: B. It affects all instances of the class. A. It only affects that specific instance. 213. Which of the following is a valid way to B. It affects all instances of the class. access a class variable in Java? C. It results in a compilation error. A. variable = 10; D. It requires synchronization to be modified. B. ClassName.variable = 10; Answer: A. It only affects that specific C. variable = ClassName; instance. D. this.variable = 10; 219. What is the main advantage of using Answer: B. ClassName.variable = 10; instance variables in Java? 214. What is the main advantage of using A. They provide a common memory space class variables in Java? shared among all instances. A. They allow for better encapsulation. B. They allow for better encapsulation. B. They are automatically initialized to zero. C. They are automatically initialized to zero. C. They are specific to each instance of the D. They are specific to each instance of the class. class. D. They provide a common memory space Answer: D. They are specific to each instance shared among all instances. of the class. Answer: D. They provide a common memory 220. What are method parameters in Java? space shared among all instances. A. Variables declared inside a class. 215. What is an instance variable in Java? B. Variables declared inside a method. A. A variable declared inside a method. C. Variables declared with the static keyword. B. A variable declared with the static keyword D. Variables declared as final. within a class. Answer: B. Variables declared inside a C. A variable declared as final within a class. method. D. A variable declared without the static 221. How are method parameters passed in keyword within a class. Java? A. By reference. A. It is retained throughout the entire B. By value. execution of the program. C. By creating a new copy of the variable. B. It is retained as long as the instance of the D. By using the this keyword. class exists. Answer: B. By value. C. It is retained as long as the method, 222. What is the purpose of method constructor, or block is executing. parameters in Java? D. It is retained until the program is closed. A. To store constants. Answer: C. It is retained as long as the B. To provide a way to access instance method, constructor, or block is executing. variables. 227.10. What is the main advantage of using C. To receive input values when calling a local variables in Java? method. A. They provide a common memory space D. To declare variables used within a method. shared among all instances. Answer: C. To receive input values when B. They allow for better encapsulation. calling a method. C. They have a shorter lifetime, freeing up ype. memory quickly. D. It results in a runtime error. D. They are specific to each instance of the Answer: A. It results in a compilation error. class. 223. What is the role of method parameters in Answer: C. They have a shorter lifetime, method overloading in Java? freeing up memory quickly. A. They are not related to method overloading. 228. What is an array in Java? B. They help differentiate between overloaded A. A collection of objects. methods. B. A variable that can hold multiple values of C. They are optional in overloaded methods. the same data type. D. They limit the number of overloaded C. A data structure that can hold both methods. primitive and non-primitive data types. Answer: B. They help differentiate between D. A variable that can hold values of different overloaded methods. data types. 224. What is the scope of a local variable in Answer: B. A variable that can hold multiple Java? values of the same data type. A. Limited to the method or block in which it 229. How are elements of an array accessed in is declared. Java? B. Accessible throughout the entire class. A. Using the this keyword. C. Accessible only within the same package. B. By creating a new instance of the array. D. Global, accessible in any class in any C. Through the array name followed by an package. index enclosed in square brackets. Answer: A. Limited to the method or block in D. By using the new keyword. which it is declared. Answer: C. Through the array name followed 225. In Java, what happens if an attempt is by an index enclosed in square brackets. made to access a local variable outside its 230. What is the index of the first element in scope? an array in Java? A. It results in a compilation error. A. 0 B. 1 C. -1 B. It results in a runtime error. D. The index is set when the array is C. The variable becomes global. initialized. D. The variable becomes inaccessible. Answer: A. 0 Answer: A. It results in a compilation error. 231. How is the length of an array determined 226. What is the lifetime of a local variable in in Java? Java? A. By using the length property. B. By counting the number of elements. C. By calling the size() method. columns. D. By using the lengthof() function. C. An array with multiple rows and one Answer: A. By using the length property. column. 232. Can the size of an array be changed after D. An array with a single column and multiple it is initialized in Java? rows. A. Yes, by using the setSize() method. Answer: B. An array with one row and B. Yes, by assigning a new value to the length multiple columns. property. 238. How are elements accessed in a two- C. No, the size is fixed once the array is dimensional array in Java? created. A. Using the array name followed by an index. D. No, arrays automatically adjust their size. B. Through the array name followed by two Answer: C. No, the size is fixed once the array indices enclosed in square brackets. is created. C. By creating a new instance of the array. 233. How is an array declared in Java? D. By using the getElement() method. A. int array = new int[]; Answer: B. Through the array name followed B. Array arr = new Array(); by two indices enclosed in square brackets. C. int[] array; 239. What is the main advantage of using a D. new Array[]; two-dimensional array over a one-dimensional Answer: C. int[] array; array in Java? 234. What is the default value of elements in A. It can store elements of different data types. an integer array in Java? B. It allows for dynamic resizing. A. 0 B. 1 C. -1 D. Null C. It provides a more organized way to Answer: A. 0 represent data in rows and columns. 235. In Java, can an array store elements of D. It has a shorter syntax. different data types? Answer: C. It provides a more organized way to A. Yes, by using the mixed keyword. represent data in rows and columns. B. Yes, as long as they are all cast to Object. 240. How is a multidimensional array C. No, an array can only store elements of the initialized in Java? same data type. A. array = new int[][]; D. No, arrays can only store primitive data B. array = new int[rows][columns]; types. C. array = new int[]{}; Answer: C. No, an array can only store D. array = new int[rows, columns]; elements of the same data type. Answer: B. array = new int[rows][columns]; 236. What happens if you try to access an 241. What is the default value of elements in a array element with an index that is out of boolean array in Java? bounds in Java? A. 0 B. 1 C. false D. true A. It results in a compilation error. Answer: C. false B. It returns the default value of the array's 242. What is the correct syntax for accepting data type. data into a one-dimensional array in Java? C. It throws an A. for (int i = 0; i < array.length; i++) ArrayIndexOutOfBoundsException. array[i] = input.nextInt(); D. It automatically adjusts the index to the B. array = input.nextInt(); nearest valid value. C. array[] = input.nextInt(); Answer: C. It throws an D. array[i] = input.nextInt() ArrayIndexOutOfBoundsException. for (int i = 0; i < array.length); 237. What is a one-dimensional array in Answer: A. for (int i = 0; i < array.length; i++) Java? array[i] = input.nextInt(); A. An array with a single element. 243. How is a two-dimensional array B. An array with one row and multiple initialized in Java? A. int array[3][4]; sorted array one element at a time. B. int array[3][4] = new int[]; C. A sorting algorithm that compares adjacent C. int array[][] = new int[3][4]; elements and swaps them if they are in the D. int array[3, 4]; wrong order. Answer: C. int array[][] = new int[3][4]; D. A sorting algorithm that selects the 244. How do you declare and initialize a two- minimum element and swaps it with the first dimensional array in Java with values? element. A. int array[][] = {{1, 2}, {3, 4}}; Answer: C. A sorting algorithm that compares B. int array[2][2] = {{1, 2}, {3, 4}}; adjacent elements and swaps them if they are C. int array[][] = new int[2][2]{{1, 2}, {3, 4}}; in the wrong order. D. int array = new int[2][2]{{1, 2}, {3, 4}}; 250. What is Linear Search? Answer: A. int array[][] = {{1, 2}, {3, 4}}; A. A searching algorithm that repeatedly 245. Which keyword is used to declare an divides the array into two halves. array in Java? B. A searching algorithm that compares A. array B. new C. int D. initialize adjacent elements and swaps them if they are Answer: B. new in the wrong order. 246. What is the main disadvantage of using C. A searching algorithm that builds the final arrays in Java? sorted array one element at a time. A. They have a fixed size. D. A searching algorithm that sequentially B. They can only store primitive data types. checks each element in the array. C. They are less memory-efficient compared to Answer: D. A searching algorithm that other data structures. D. They cannot be used in loops. Answer: A. They have a fixed size. 247. What is Selection Sort? s A. A sorting algorithm that repeatedly divides equentially checks each element in the array. the array into two halves. 251. In Linear Search, how many B. A sorting algorithm that builds the final comparisons are made in the worst case for an sorted array one element at a time. array of size n if the element is not present? C. A sorting algorithm that selects the A. n maximum element and moves it to the end of B. n - 1 the array. C. (n^2)/2 D. A sorting algorithm that selects the D. 2n minimum element and swaps it with the first Answer: A. n element. 251. Which of the following is true about Answer: D. A sorting algorithm that selects the Linear Search? minimum element and swaps it with the first A. It is suitable for sorted arrays only. element. B. It is an in-place searching algorithm. 248. In Selection Sort, how many total swaps C. It is less efficient than binary search. are made for an array of size n? D. It cannot be implemented in Java. A. n Answer: C. It is less efficient than binary B. n - 1 search. C. (n^2) 252. What is Binary Search? D. n*n A. A searching algorithm that sequentially Answer: B. n - 1 checks each element in the array until a 249.What is Bubble Sort? match is found. A. A sorting algorithm that repeatedly divides B. A searching algorithm that divides the array the array into two halves. into two halves and recursively searches each B. A sorting algorithm that builds the final half. C. A searching algorithm that compares Answer: D. It will throw an adjacent elements and swaps them if they are ArrayIndexOutOfBoundsException. in the wrong order. 258. Can the length of an array in Java be D. A searching algorithm that selects the changed once it is initialized? maximum element and moves it to the end of A. Yes, by using the resize() method. the array. B. Yes, by assigning a new value to the length Answer: B. A searching algorithm that divides attribute. the array into two halves and recursively C. No, the length is fixed once the array is searches each half. created. 253. Which of the following is true about D. No, arrays automatically adjust their Binary Search? length. A. It is suitable for unsorted arrays only. Answer: C. No, the length is fixed once the B. It is an in-place searching algorithm. array is created. C. It is less efficient than linear search. 259. How are strings created in Java? D. It requires the array to be sorted. A. String str = new String("Hello"); Answer: D. It requires the array to be sorted. B. String str = "Hello"; 254 What is the main limitation of Binary C. Both A and B Search? D. None of the above A. It cannot handle large datasets. Answer: C. Both A and B B. It has a high time complexity in the worst 260. Which method is used to compare two case. strings for equality in a case-sensitive C. It requires the array to be sorted. manner? D. It may have to traverse the entire array A. equals() even if the element is found early. B. equalsIgnoreCase() Answer: C. It requires the array to be sorted. C. compare() Length Function for Arrays in Java: D. compareTo() 255. How is the length of an array obtained in Answer: A. equals() Java? 261. What is the purpose of the trim() method A. array.size() in the String class? B. array.length() A. To remove all occurrences of a specified C. length(array) substring. D. sizeOf(array) B. To remove leading and trailing whitespaces. Answer: B. array.length() C. To concatenate two strings. 256.3. In Java, what is the return type of the D. To convert the string to uppercase. length attribute for arrays? Answer: B. To remove leading and trailing A. int whitespaces. B. double 261. Can a String object be modified once it is C. boolean created in Java? D. String A. Yes, strings are mutable in Java. Answer: A. int B. No, strings are immutable in Java. 257. What will happen if you try to access an C. It depends on the length of the string. element at an index greater than or equal to D. It depends on the method used to create the length of the array? the string. A. It will return the element at that index. Answer: B. No, strings are immutable in Java. B. It will result in a compilation error. 262. Which method is used to check if a string C. It will return null. starts with a specified prefix in Java? D. It will throw an A. startsWith() ArrayIndexOutOfBoundsException. B. beginWith() C. prefixWith() A. The Unicode value of the character at a D. initiateWith() specified index. Answer: A. startsWith() B. The ASCII value of the character at a 263. What is the purpose of the replace() specified index. method in the String class? C. The character at a specified index. A. To remove a specified substring. D. The index of a specified character in the B. To replace a substring with another string. substring. Answer: C. The character at a specified index. C. To concatenate two strings. 269. Which method is used to remove leading D. To convert the string to uppercase. and trailing whitespaces from a string in Java? Answer: B. To replace a substring with A. trim() another substring. B. strip() 264. Which method is used to convert a C. removeWhitespaces() primitive type to a String in Java? D. clean() A. toString() Answer: A. trim() B. convertToString() 270. How can you initialize a String array in C. stringify() Java with values? D. asString() A. String[] names = {"John", "Jane", "Bob"}; Answer: A. toString() B. String names[] = new String[] {"John", 265. What is the purpose of the valueOf() "Jane", "Bob"}; method in the String class? C. String[] names = new String(3) {"John", A. To convert a string to a primitive data type. "Jane", "Bob"}; B. To create a new string representation of an D. String names = {"John", "Jane", "Bob"}; object. Answer: A. String[] names = {"John", "Jane", C. To obtain the value of a variable. "Bob"}; D. To concatenate two strings. 270. What is the purpose of the trim() function Answer: B. To create a new string in Java? representation of an object. A. Removes all characters from the string. 266.19. What is the purpose of the indexOf() B. Converts the string to uppercase. method in the String class? C. Removes leading and trailing whitespaces A. To obtain the index of the last occurrence of from the string. a specified character. D. Replaces specified characters with another B. To search for a substring within a string character. and return its starting index. Answer: C. Removes leading and trailing C. To check if a string contains a specified whitespaces from the string. character. 271. What is the return type of the trim() D. To find the length of a string. function in Java? Answer: B. To search for a substring within a A. void string and return its starting index. B. String 267. Which method is used to concatenate C. boolean two strings in Java? D. int A. concat() Answer: B. String B. combine() 272. Can the toLowerCase() function modify C. append() the original string in Java? D. merge() A. Yes, it modifies the original string. Answer: A. concat() B. No, it creates a new string with characters 268. What does the charAt() method of the converted to lowercase. String class return? C. It depends on the length of the string. D. It depends on the method used to call A. Converts the string to lowercase. toLowerCase(). B. Concatenates the specified string to the end Answer: B. No, it creates a new string with of the original string. characters converted to lowercase. C. Removes leading and trailing whitespaces. 273. How is the length() function used in D. Converts all characters in the string to Java? uppercase. A. int result = size(str); Answer: B. Concatenates the specified string B. int result = str.size(); to the end of the original string. C. length(str); 278.2. How is the concat(String str) function D. int result = str.length(); used in Java? Answer: D. int result = str.length(); A. String result = concatenate(str1, str2); 274. How is the charAt(int n) function used in B. String result = str1.concat(str2); Java? C. concat(str1, str2); A. char result = getChar(str, n); D. String result = str2.concat(str1); B. char result = str.charAt(n); Answer: B. String result = str1.concat(str2); C. charAt(n, str); 279. What is the return type of the D. char result = charAt(str, n); concat(String str) function in Java? Answer: B. char result = str.charAt(n); A. void 274. What is the purpose of the indexOf(char B. String ch) function in Java? C. boolean A. Converts the string to lowercase. D. int B. Returns the index of the first occurrence of Answer: B. String a specified character. 280.What is the purpose of the equals(String C. Removes leading and trailing whitespaces. str) function in Java? D. Converts all characters in the string to A. Converts the string to lowercase. uppercase. B. Checks if the string is equal to the specified Answer: B. Returns the index of the first string. occurrence of a specified character. C. Removes leading and trailing whitespaces. 275. What is the purpose of the D. Converts all characters in the string to lastIndexOf(char ch) function in Java? uppercase. A. Converts the string to lowercase. Answer: B. Checks if the string is equal to the B. Returns the index of the last occurrence of specified string. a specified character. 280.How is the equals(String str) function C. Removes leading and trailing whitespaces. used in Java? D. Converts all characters in the string to A. boolean result = checkEquality(str1, str2); uppercase. B. boolean result = str1.equals(str2); Answer: B. Returns the index of the last C. equals(str1, str2); occurrence of a specified character. D. boolean result = str2.equals(str1); 276. What happens if the specified character Answer: B. boolean result = str1.equals(str2); is not found in the string when using 281. What is the return type of the lastIndexOf(char ch)? equals(String str) function in Java? A. It returns -1. A. void B. It throws an IndexOutOfBoundsException. B. String C. It returns the last index of the string. C. boolean D. It returns 0. D. int Answer: A. It returns -1. Answer: C. boolean 277.1. What is the purpose of the 282. How does the equals(String str) function concat(String str) function in Java? handle case sensitivity? A. It is case-sensitive. A. void B. It converts both strings to lowercase before B. String comparison. C. boolean C. It converts both strings to uppercase before D. int comparison. Answer: D. int D. It ignores case while comparing. 288. Which of the following statements is true Answer: A. It is case-sensitive. about the compareTo(String str) function? 283. What is the purpose of the A. It converts the string to lowercase. equalsIgnoreCase(String str) function in Java? B. It only checks if the lengths of the two A. Converts the string to lowercase. strings are equal. B. Checks if the length of the string is equal to C. It compares two strings lexicographically. the specified string. D. It removes leading and trailing whitespaces. C. Removes leading and trailing whitespaces. Answer: C. It compares two strings D. Checks if the content of the string is equal lexicographically. to the specified string, ignoring case. 289. How does the compareTo(String str) Answer: D. Checks if the content of the string function determine the result? is equal to the specified string, ignoring case. A. It compares the lengths of the two strings. 284.2. How is the equalsIgnoreCase(String str) B. It compares the content of the two strings, function used in Java? ignoring case. A. boolean result = C. It compares the content of the two strings checkEqualityIgnoreCase(str1, str2); lexicographically. B. boolean result = D. It converts both strings to uppercase before str1.equalsIgnoreCase(str2); comparison. C. equalsIgnoreCase(str1, str2); Answer: C. It compares the content of the two D. boolean result = strings lexicographically. str2.equalsIgnoreCase(str1); 290. What is the purpose of the Answer: B. boolean result = compareToIgnoreCase(String str) function in str1.equalsIgnoreCase(str2); Java? 285. How does the equalsIgnoreCase(String A. Converts the string to lowercase. str) function handle case sensitivity? B. Compares two strings lexicographically, A. It is case-sensitive. ignoring case. B. It converts both strings to lowercase before C. Removes leading and trailing whitespaces. comparison. D. Checks if the string is equal to the specified C. It converts both strings to uppercase before string. comparison. Answer: B. Compares two strings D. It ignores case while comparing. lexicographically, ignoring case. Answer: D. It ignores case while comparing. 291. What is the return type of the 286. What is the purpose of the compareToIgnoreCase(String str) function in compareTo(String str) function in Java? Java? A. Converts the string to lowercase. A. void B. Compares two strings lexicographically. B. String C. Removes leading and trailing whitespaces. C. boolean D. Checks if the string is equal to the specified D. int string. Answer: D. int Answer: B. Compares two strings 292. What is the output of the following Java lexicographically. code snippet? 287. What is the return type of the String text1 = "Hello"; String text2 = "hello"; int compareTo(String str) function in Java? result = text1.compareToIgnoreCase(text2); System.out.println(result); A. 0 C. It replaces all occurrences of the specified B. 1 character with a new character. C. -1 D. It removes leading and trailing whitespaces. D. Hello Answer: C. It replaces all occurrences of the Answer: A. 0 specified character with a new character. 293. Which of the following statements is true 298. What happens if the specified old about the compareToIgnoreCase(String str) character is not found in the string when function? using replace(char oldChar, char newChar)? A. It converts the string to lowercase. A. It throws an exception. B. It only checks if the lengths of the two B. It returns the original string unchanged. strings are equal. C. It replaces the character with an empty C. It compares two strings lexicographically, character. ignoring case. D. It returns null. D. It removes leading and trailing whitespaces. Answer: B. It returns the original string Answer: C. It compares two strings unchanged. lexicographically, ignoring case. 299. What is the purpose of the substring(int 294. What is the purpose of the replace(char beginIndex) function in Java? oldChar, char newChar) function in Java? A. Converts the string to lowercase. A. Replaces the specified character with a new B. Retrieves a substring starting from the character in the string. specified index. B. Converts the string to lowercase. C. Removes leading and trailing whitespaces. C. Removes leading and trailing whitespaces. D. Checks if the string is equal to the specified D. Checks if the string is equal to the specified string. string. Answer: B. Retrieves a substring starting from Answer: A. Replaces the specified character the specified index. with a new character in the string. 295. What is the return type of the replace(char oldChar, char newChar) function in Java? A. void 300. What is the return type of the B. String substring(int beginIndex) function in Java? C. boolean A. void D. int B. String Answer: B. String C. boolean 296. What is the output of the following Java D. int code snippet? Answer: B. String String text = "apple"; String result = 301. What is the output of the following Java text.replace('p', 'm'); System.out.println(result); code snippet? A. "ample" String text = "Hello, World!"; String result = B. "appme" text.substring(7); System.out.println(result); C. "apple" A. "World!" D. "amme" B. "Hello, World!" Answer: A. "ample" C. "ello, World!" 297. Which of the following statements is true D. "!" about the replace(char oldChar, char Answer: A. "World!" newChar) function? 302. What happens if the specified beginIndex A. It converts the string to lowercase. is greater than or equal to the length of the B. It only replaces the first occurrence of the string? specified character. A. It throws an exception. A. It throws an exception. B. It returns an empty string. B. It returns an empty string. C. It returns the original string unchanged. C. It returns the original string unchanged. D. It removes the characters from the end. D. It removes the characters from the end. Answer: B. It returns an empty string. Answer: A. It throws an exception. 303. What is the purpose of the substring(int 308. What is the purpose of the beginIndex, int endIndex) function in Java? startsWith(String str) function in Java? A. Converts the string to lowercase. A. Checks if the string is equal to the specified B. Retrieves a substring starting from the string. specified index up to, but not including, the B. Determines if the string ends with the specified end index. specified suffix. C. Removes leading and trailing whitespaces. C. Checks if the string starts with the specified D. Checks if the string is equal to the specified prefix. string. D. Converts the string to lowercase. Answer: B. Retrieves a substring starting from Answer: C. Checks if the string starts with the the specified index up to, but not including, specified prefix. the specified end index. 309. What is the return type of the 304. What is the return type of the startsWith(String str) function in Java? substring(int beginIndex, int endIndex) A. void function in Java? B. String A. void C. boolean B. String D. int C. boolean Answer: C. boolean D. int 310. What is the output of the following Java Answer: B. String code snippet? 305. What is the output of the following Java String text = "Hello, World!"; boolean result = code snippet? text.startsWith("Hello"); String text = "Hello, World!"; String result = System.out.println(result); text.substring(7, 12); A. true System.out.println(result); B. false A. "World" C. Hello B. "Hello" D. World! C. "World!" Answer: A. true D. "Worl" 311.What is the purpose of the Answer: A. "World" endsWith(String str) function in Java? 306. How does the substring(int beginIndex, A. Checks if the string is equal to the specified int endIndex) function handle negative values string. of beginIndex and endIndex? B. Determines if the string starts with the A. It throws an exception. specified prefix. B. It starts the substring from the end of the C. Checks if the string ends with the specified string. suffix. C. It ignores the negative sign. D. Converts the string to lowercase. D. It replaces negative values with zero. Answer: C. Checks if the string ends with the Answer: A. It throws an exception. specified suffix. 307. What happens if the specified beginIndex 312. What is the return type of the is greater than or equal to the length of the endsWith(String str) function in Java? string when using substring(int beginIndex, A. void int endIndex)? B. String C. boolean A. String result = Double.valueOf(3.14); D. int B. String result = valueOf(3.14); Answer: C. boolean C. String result = String.valueOf(3.14); 313. What is the purpose of the valueOf D. String result = "3.14".valueOf(); method in Java? Answer: C. String result = A. Converts a string to an integer. String.valueOf(3.14); B. Converts different types of values to their 319. In which scenario is the valueOf method string representations. particularly useful? C. Concatenates two strings. A. When you want to convert a string to an D. Checks if two strings are equal. integer. Answer: B. Converts different types of values B. When you want to check if two strings are to their string representations. equal. 314. Which of the following is a correct usage C. When you want to convert different types of of the valueOf method for converting an values to their string representations. integer to a string? D. When you want to perform mathematical A. String result = valueOf(42); operations on strings. B. String result = Integer.valueOf(42); Answer: C. When you want to convert different C. String result = String.valueOf(42); types of values to their string representations. D. String result = "42".valueOf(); 320. In which Java class is the valueOf Answer: C. String result = String.valueOf(42); method defined? 315. What is the return type of the valueOf A. Math method? B. Integer A. void C. Scanner B. String D. String C. int Answer: D. String D. boolean 321. What is the output of the following Java Answer: B. String code snippet? 316. Which of the following is a correct usage String str1 = "Hello"; String str2 = "World"; of the valueOf method for converting a boolean str1.concat(str2); System.out.println(str1); to a string? System.out.println(str1.concat(str2)); A. String result = valueOf(true); A. HelloWorld, HelloWorld B. String result = Boolean.valueOf(true); B. Hello, HelloWorld C. String result = String.valueOf(true); C. HelloWorld, Hello D. String result = "true".valueOf(); D. Hello, Hello Answer: C. String result = String.valueOf(true); Answer: B. Hello, HelloWorld 317. How is the valueOf method helpful when 322. What is the output of the following Java working with different data types? code snippet? A. It converts any data type to an integer. String str = " Java is "; str.trim(); B. It converts any data type to its binary System.out.println(str.length()); representation. A. 7 C. It converts different types of values to their B. 8 string representations. C. 9 D. It converts a string to a double. D. 10 Answer: C. It converts different types of values Answer: C. 9 to their string representations. 323. What is the output of the following Java 318. Which of the following is a correct usage code snippet? of the valueOf method for converting a double String str = "Hello, World!"; to a string? System.out.println(str.substring(7, 12).toUpperCase()); A. "WORLD" A. "P" B. "World" B. "" (empty string) C. "Worl" C. "Pr" D. "WORLD!" D. IndexOutOfBoundsException Answer: A. "WORLD" Answer: B. "" (empty string) 324. What is the output of the following Java 329. What is the output of the following Java code snippet? code snippet? String str = "JavaProgramming"; String str = "Hello, World!"; System.out.println(str.replace("a", "X")); System.out.println(str.substring(0, A. "JXvXProgrXmming" 5).concat(str.substring(7, 12))); B. "JvXProgrXmming" A. "HelloWorld" C. "JXvXProgrXXmming" B. "Hello, World!" D. "JavaProgramming" C. "HelloWorld!" Answer: A. "JXvXProgrXmming" D. "Hello" 325. What is the output of the following Java Answer: A. "HelloWorld" code snippet? 330. What is the output of the following Java String str = "Hello,World"; code snippet? System.out.println(str.substring(0, 5) + String str = "Hello, World!"; str.substring(7)); System.out.println(str.toUpperCase().charAt(7) A. "Hello,World" ); B. "HelloWorld" A. 'W' C. "HelloWorld," B. 'w' D. "World,Hello" C. ' ' (space) Answer: B. "HelloWorld" D. 'o' 326. What is the output of the following Java Answer: A. 'W' code snippet? 331. What is the output of the following Java String str = "Hello, World!"; code snippet? System.out.println(str.indexOf("World")); String str = "JavaProgramming"; A. 0 System.out.println(str.replaceAll("Java", "")); B. 7 A. "Programming" C. -1 B. "Java" D. 6 C. "JavaProgramming" Answer: B. 7 D. "" 327. What is the output of the following Java Answer: A. "Programming" code snippet? 332. What is the output of the following Java String str1 = "Hello"; String str2 = "Hello"; code snippet? String str3 = new String("Hello"); String str = "Hello, World!"; System.out.println(str1.equals(str2) && System.out.println(str.substring(7).toUpperCa str1.equals(str3)); se().charAt(2)); A. true A. 'O' B. false B. 'W' C. Compilation error C. 'R' D. Runtime error D. 'D' Answer: A. true Answer: A. 'O' 328. What is the output of the following Java 333. What is the output of the following Java code snippet? code snippet? String str = "JavaProgramming"; String str = "Java"; System.out.println(str.substring(4, 4)); System.out.println(str.substring(0, 2).concat(str.substring(2).toUpperCase())); A. "Java" D. It refers to the current method being B. "JaVA" executed C. "JAva" Answer: A. It refers to the current instance of D. "JA" the class Answer: D. "JA" 340. What is the purpose of the 'break' 334. Which of the following is a valid Java keyword in Java? keyword for defining a constant variable? A. To terminate a loop or switch statement A. static B. To skip the next iteration of a loop B. final C. To exit the program C. constant D. To skip the current block of code D. variable Answer: A. To terminate a loop or switch Answer: B. final statement 335. In Java, which keyword is used to 341. Which keyword is used to define a declare a method that does not return any subclass in Java? value? A. extends A. void B. subclass B. null C. inherits C. none D. sub D. return Answer: A. extends Answer: A. void 342. In Java, which keyword is used to specify 336. What is the purpose of the 'static' that a variable or method belongs to the class keyword in Java? and not to instances of the class? A. To define a constant variable A. static B. To declare a variable that can be modified B. instance C. To indicate that a method belongs to the C. classvar class, not an instance of the class D. nonstatic D. To create an instance of a class Answer: A. static Answer: C. To indicate that a method belongs 343. Which keyword is used to define a to the class, not an instance of the class package in Java? 337. Which keyword is used for dynamic A. package memory allocation in Java? B. define A. new C. namespace B. malloc D. module C. alloc Answer: A. package D. create 344. In Java, which keyword is used to Answer: A. new prevent the execution of a loop or switch 338. Which keyword is used to prevent statement? inheritance of a class in Java? A. stop A. prevent B. halt B. final C. break C. stop D. exit D. noinherit Answer: C. break Answer: B. final 346. What is the purpose of the 'continue' 339. What does the 'this' keyword refer to in keyword in Java? Java? A. It terminates the loop A. It refers to the current instance of the class B. It skips the rest of the code in the loop and B. It represents the superclass of a class continues with the next iteration C. It is used to create a new instance of a class C. It breaks out of the loop D. It restarts the loop from the beginning Answer: B. It skips the rest of the code in the void updateArray(int[] arr) loop and continues with the next iteration { 347. What is the default method of parameter for (int i = 0; i < arr.length; i++) passing in Java? { arr[i] = arr[i] * 2; A. Call by Value }} B. Call by Reference If you call updateArray(new int[]{1, 2, 3});, C. Call by Object what will be the value of the array after the D. Call by Name method call? Answer: A. Call by Value A. {1, 2, 3} 348. In Call by Value, what is passed to the B. {2, 4, 6} method? C. {3, 6, 9} A. The actual value of the argument D. {4, 8, 12} B. The memory address of the argument Answer: B. {2, 4, 6} C. A reference to the argument 353.Operators with higher precedence are D. The type of the argument evaluated before operators with relatively Answer: A. The actual value of the argument lower precedence. Arrange the operators given 349. Which of the following is true regarding below in order of higher precedence to lower Call by Reference in Java? precedence. A. Java strictly follows Call by Reference (i) && (ii) % (iii) >= (iv) ++ B. Objects are always passed by reference in 1. (iv), (i), (iii), (ii) Java 2. (iv), (iii), (ii), (i) C. Java does not support Call by Reference 3. (iv), (ii), (iii), (i) D. Call by Reference is the default in Java 4. (i), (ii), (iii), (iv) Answer: C. Java does not support Call by 354.Name the type of error in the statement Reference given below: int r=100/0; 1. Syntax 2. Runtime 3. Logical 350. In Call by Reference, changes made to 4. None of the above parameters inside the method: 355. Method that accepts a string without any A. Affect the original values space is _______ B. Do not affect the original values 1. next() C. Are only visible inside the method 2. nextLine() D. Depend on the data type 3. nextInt() Answer: A. Affect the original values 4. None of the above 351. Consider the following method 356.The wrapper class to which the method declaration: parseInt() belongs to void updateValue(int x) 1. integer { x = x * 2; } 2. Int If you call updateValue(5);, what will be the 3. Integer value of x after the method call? 357. Intermediate code obtained after A. 5 compilation B. 10 1. Source code C. 15 2. Byte Code D. 20 3. Object code Answer: A. 5 358. The method with the same name as of 352. Consider the following method the class and which does not have a return declaration: data type is called as 1. Constructor 2. Loop is executed 3 times and the output is 2. Function 10 3. Method 4 3. Loop is executed 2 times and the output is 359. The statement to stop the execution of a 10. construct. 366. When primitive data type is converted to 1. System.exit(0) its corresponding object of its class, it is called 2. break as ___________. 3. STOP (a) Boxing 360. Invoking a function by passing the (b) Explicit type conversion objects of a class is termed as (c) Unboxing 1. Call by value (d) Implicit type conversion 2. call by reference 367.A variable that is bounded to the object 3. call by method itself is called as: 361.Give the output of the following (a) Instance variable x + = x++ + ++ x + --x + x; [ x = 5 ] (b) class variable 1. 29 (c) Local variable 2. 28 (d) Argument variable 3. 26 368.Give the output of the following code: 4. 25 String A ="26.0", B="74.0"; 362. if ( a > b ) double C= Double .parseDouble(A); System.out.println(a+b); double D = Double .parseDouble(B); System.out.println (a*b); when a = 5 and b = 7 System.out.println((C+D)); 1. 12, 35 (a) 26 2. 35 (b) 74 3. 35, 12 6 (c) 100.0 363. String x = (a >= 90) ? "excellent" : "best"; (d) 2674 when a = 90 369.Wrapper classes are available in 1. best __________ package. 2. excellent (a) java.io 3. excellentbest (b) java.util 364. switch ( x ) (c) java.lang { case 'a' : System.out.println("Discipline"); (d) java.awt case 'b' : System.out.println ("Dedication"); 370. The logical operator which is an unary break; operator: case 'c' : System.out.println("Commitment"); (a) && default : System.out.println("Success"); (b) || } when x='A' (c) ! 1. Discipline (d) >> 2. Dedication 371. The Scanner class is a……class. 3. Success (a)Primitive 365. int n=1000; (b)Derived while (n>10) (c)Wrapper { n=n/10; (d)super class } Ans: (b)Derived System.out.println(n); 372. for(k=1;k<=2;k++) How many time the loop is executed and what { is the output? for(m=1;m<=4;m++) 1. Loop is executed 2 times and the output is { 100 System.out.println(m*2); }} 381. Assigning value to a variable during How many times the inner loop is executed? declaration is called. (a)4 times a. Declaration b. Assignment (b)8 times c. Initialisation d. None of these (c)2 times Ans. c. Initialisation (d)16 times 382. Which among the following is used to 373.Name the type of error that occurs for the represent single-line comment? following statement: a. // b. /* c. \\ d. <!— System.out.println(Math.sqrt(24 - 25)); Ans. a. // (a)Syntax error 383. Which among the following is a logical (b)run time error error? (c)logical error a. Missing semicolon (d)no error b. Mismatched braces in classes and methods. 374.Which among the following operator is c. Misspelled keywords and identifiers. used to access individual members of an d. Addition is required but subtraction is object? performed. a. . (dot) b. + (plus) Ans. d. Addition is required but subtraction is c. – (minus) d. / (divide) performed. Ans. a. . (dot) 384. Which among the following represents a 375. Which among the following modifier is syntax error? used in a ‗class‘? a. Dividing an integer by zero. a. public b. default b. Accessing an element that is out of bounds c. Both a and b d. None of these of an array. Ans. c. Both a and b c. Trying to store a value which is 376. Which among the following is a valid incompatible to a certain data-type. class name? d. Missing semicolon a. Simple Interest b. SimpleInterest Ans. d. Missing semicolon c. 1SimpleInterest d. Simple@Interest 385. What is the name given to a memory Ans. b. SimpleInterest location called in Java? 377.Which among the following is a valid float a. Variable b. Constant literal? c. Data Type d. None of these a. 12.36f b. 12.36F Ans. a. Variable c. 12.36 d. Both a and b 386.How is encapsulation implemented in a Ans. d. Both a and b program? 378. Which among the following is a valid a. Using a class b. Using only Functions octal integer literal? c. Using only Variables d. None of these a. 0178 b. 675 Ans. a. Using a class c. 0675 d. 0X675 387.Once a function is defined, it can be Ans. c. 0675 invoked repeatedly. What is this feature 379. Which among the following is a valid called? method of initialising? a. Interface b. Reusability a. boolean f=true; b. boolean f=True; c. Restructuring d. All of these c. boolean f=‘true‘; d. None of these Ans. b. Reusability Ans. a. boolean f=true; 388. A type of parameter that are used to 380. Which among the following is not a identify what data is to be passed to a function punctuator? is called: a. ; semicolon b. , comma a. Formal parameter b. Actual parameter c. : colon d. . dot c. Both a and b d. None of these Ans. a. Formal parameter 389.The parameter list in a function definition 397. What access specifier for a constructor is called: allows you to create an object only within the a. Function prototype b. Function signature class? c. Both a and b d. None of these a. public b. private Ans. b. Function signature c. protected d. default 390. The first line of the function definition is Ans. b. private called: 398. Predict the output of the following a. Function prototype b. Function signature program: c. Both a and b d. None of these class T Ans. a. Function prototype { int t = 20; 391. The number of values that a function can T() return is: {t = 40;} a. 1 b. 2 c. 3 d. 4 public static void main( ) Ans. a. 1 { 392. A local variable in a function has its T t1 = new T(); scope: System.out.println(t1.t); a. Limited within the function }} b. Can be accessed anywhere within the same a. 20 b. 40 class c. Compiler Error d. None of these c. No limitation at all Ans. b. 40 d. None of these 399. The following code contains one Ans. a. Limited within the function compilation error, find it? 393. Which of the following is not applicable public class Test { for a constructor function? Test() { } // line 1 a. It has the same name as the class. static void Test() { this(); } // line 2 b. It has no return-type public static void main( ) { // line 3 c. It is usually used for initialisation. Test(); // line 4 d. It can be invoked using an object like any }} other member function. a. At line 1, constructor Tester must be Ans. d. It can be invoked using an object like marked public like its class any other member function. b. At line 2, constructor call 394. If the name of a class is ‗Number‘, what c. At line 3, compilation error, ambiguity can be the possible name for its constructor? problem, compiler can‘t determine whether a a. Number b. number constructor c. No d. No d. At line 4 Ans. a. Number Ans. b. At line 2, constructor call 395. Which among the following is a type of 400. Which of the following is not true for constructor? static block? a. Parameterised constructor a. It is used to initialise static variables. b. Non-parameterised constructor b. It gets executed when a class gets loaded in c. Both a and b the memory. d. None of these c. It can print the content of instance Ans. c. Both a and b variables. 396. If constructors are overloaded, what d. It begins with the static keyword. differentiates it? Ans. c. It can print the content of instance a. Parameter list b. Return type variables. c. Both a and b d. None of these 408. What is, converting a primitive value into an object of the corresponding wrapper class called? a. Autoboxing b. Unboxing 401.Which of the following is not a wrapper c. Type Casting d. All of these class? Ans. a. Autoboxing a. Byte b. Int 409. Which among the following function is c. Long d. Float used to check whether a given character is a Ans. b. Int tab space or not? 402. Which of the following is valid method of a. isTab() b. isTabSpace() initialising? c. isSpace() d. isWhitespace() a. Integer a=new (5); Ans. d. isWhitespace() b. Integer a=Integer(5); 410. Which access specifier allows c. Integer a=new Integer(5); accessibility of a member only within the same d. Integer a=new (―5‖); class where it is declared? Ans. d. Integer a=new (―5‖); a. public b. private 403. If s=―123‖, which among the following c. protected d. default will convert it to an integer? Ans. b. private a. int a=Integer(s); 411. Wrapping up of data and method into a b. int a=(int)s; single unit is called _________. c. int a=parseInt(s); a. Encapsulation b. Abstraction d. int a=Integer.parseInt(a); c. Inheritance d. Polymorphism Ans. d. int a=Integer.parseInt(a); Ans. a. Encapsulation 404. Which among the following is valid 412. An OOP feature that allows all members character initialisation? of a class to be the members of another class. a. Character c=new Character(‗c‘); a. Encapsulation b. Abstraction b. Character c=new Character(―c‖); c. Inheritance d. Polymorphism c. Both a and Ans. c. Inheritance b d. None of these 413. Which keyword allows Inheritance? Ans. a. Character c=new Character(‗c‘); a. extend b. extends 405. Which among the following methods c. for d. protected return a true or a false? Ans. b. private a. toLowerCase() 414. Which access specifier allows b. toUpperCase() accessibility by all classes in the same c. parseInt() package, but only by subclasses in a different d. isUpperCase() package? Ans. d. isUpperCase() a. public b. private 406. What package is a part of the wrapper c. protected d. default class which is imported by default into all Ans. c. protected Java programs? 415. A static member a is declared in a class a. java.util b. java.lang named ‗Myclass‘, write the statement to c. java.awt d. None of these initialise it with 5, from a function in another Ans. b. java.lang class. 407. Which class is inherited by the Character a. a=5; b. a of Myclass=5; and Boolean wrapper classes? c. Myclass.a=5; d. a.Myclass=5; a. Object b. Number Ans. c. Myclass.a=5; c. Both a and b d. None of these 416. Which among the following best Ans. a. Object describes encapsulation? a. It is a way of combining various data (b) Binary search is less efficient than the members into a single unit linear search b. It is a way of combining various member (c) Binary search is more efficient than the functions into a single unit sequential search c. It is a way of combining various data (d) Binary search is as efficient as the members and member functions into a single sequential search unit which can operate on any data 423. Which element is num[9] of the array d. It is a way of combining various data num ? members and member functions that operate (a) 8th (b) 9th (c) 10th (d) 11th on those data members into a single unit 424. The class that helps in converting Ans. d. It is a way of combining various data primitive or fundamental datatypes into object members and member functions that operate types is known as __________ on those data members into a single unit (a) Scanner class (b) Wrapper class 417. If data members are private, what can we (c) Object class (d) Character class do to access them from the class object? 425. Write the output of the following: a. Create public member functions to access short x=50; those data members String s1=String.valueOf(x+60); b. Create private member functions to access System.out.println(s1); those data members (a) 5060 c. Create protected member functions to (b) 110 access those data members (c) x60 d. Private data members can never be (d) 50 accessed from outside the class 426.This type of variable‘s value is common Ans. a. Create public member functions to for all the objects created from the same class. access those data members (a) static 418. Which feature can be implemented using (b) local encapsulation? (c) instance a. Inheritance b. Abstraction (d) formal c. Polymorphism d. Overloading 427. Which of the following option leads to the Ans. b. Abstraction portability and security of Java? 419. How can Encapsulation be achieved? a) Bytecode is executed by JVM a. Using Access Specifiers b) The applet makes the Java code secure and b. Using only private members portable c. Using inheritance c) Use of exception handling d. Using Abstraction d) Dynamic binding between objects Ans. a. Using Access Specifiers 428. Which of the following is not a Java 420. An instance variable……………. features? (a) Needs an instance to access it a) Dynamic (b) Does not need an instance to access it b) Architecture Neutral (c) Can be accessed via the class name c) Use of pointers (d) Is declared with static keyword d) Object-oriented 421. The class which get inherited is knows as 429. The \u0021 article referred to as a ……………. a) Unicode escape sequence (a) Parent class (b) Super class b) Octal escape (c) Base class (d) All of these c) Hexadecimal 422. Which of the following statements is d) Line feed true? 430.What does the expression float a = 35 / 0 (a) Binary search is less efficient than the return? sequential search a) 0 b) Not a Number b) xyx c) Infinity c) yyx d) Run time exception d) xzy 431. Evaluate the following Java expression, if 436.Find the output: x=3, y=5, and z=10 : ++z + y - y + z + x++ char ch = 'F'; a) 24 int m = ch; b) 23 m=m+5; c) 20 System.out.println(m + " " + ch); d) 25 a) m F 432. Which of the following for loop b) 75 F declaration is not valid? c) 75 80 a) for ( int i = 99; i >= 0; i / 9 ) d) F 75 b) for ( int i = 7; i <= 77; i += 7 ) 437. Find the output of the following c) for ( int i = 20; i >= 2; - -i ) statement: d) for ( int i = 2; i <= 20; i = 2* i ) System.out.println("A picture is worth \t \"A 433. Which keyword is used for accessing the thousand words.\" "); features of a package? a) A picture is worth "A thousand words." a) Package b) A picture is worth "A thousand words." b) import c) A picture is worth A thousand words. c) extends d) A picture is worth A thousand words. d) export 438. Give output of the following function 433. What is the range of short data type in definition and also write the mathematical Java? operation they carry out: a) -128 to 127 void test3(char c) b) -32768 to 32767 { c) -2147483648 to 2147483647 System.out.println( (int) c); d) None of the mentioned } 434. What is the range of byte data type in if 'm' is passed to c. Java? a) m a) -128 to 127 b) M b) -32768 to 32767 c) 109 c) -2147483648 to 2147483647 d) None of the above d) None of the mentioned 439. Give the output of the snippet: 434. Which of these cannot be used for a int p = 9; variable name in Java? while (p<=15) a) identifier { b) keyword p++; c) identifier & keyword if(p== 10) d) None of the mentioned continue; 435. What is the output produced by the System.out.print(p); following lines of program code? } char x, y; a) 1111121213134 x = 'y'; b) 111213141516 System.out.println(x); c) 111213151616 y = 'z'; d) 111212141516 System.out.print(y); 440. Give output of the following function x = y; definition and also write the mathematical System.out.print(x); operation they carry out: a) yzz void test1(int n) { 36 for(int x=1; x<=n; x++) 443. Give the output of the following Java if(n%x == 0) program snippet based on nested loops: System. out.print(x); int x,y; } if 12 is passed to n. for(x=1; x<=5; x++) a) 123466 { b) 1234612 for(y=1; y<x; y++) c) 1234675 { d) 123456 if(x == 4) 441. Which loop is given in the code below: break; void test2(int a, int b) System.out.print(y); { } while( a != b) System.out.println( ); { } if ( a > b) a) 1 a = a — b; 12 else 1234 a = b — a; b) 1 } 12 System.out.println(a); 1234 } c) 1 if 4 and 17 are passed to the function. 123 a) Nested Loop 1234 b) Empty Loop d) 1 c) Infinite Loop 12 d) Invalid Loop 123 442. Give the output of the following Java program snippet based on nested loops: 444. Give the output of the following Java int y,p; program snippet based on nested loops: for (int x=1; x<=3; x++) int a,b; { for (a=1; a<=2; a++) for (y=1; y<=2; y++) { { for (b= (64+a); b<=70; b++) p = x * y; System.out.print((char) b); System.out.print(p); System.out.println( ); } } System.out.println( ); a) ABCDEF } ABCDEF a) 24 b) ABCDEF 12 ABCDE 7 36 c) ABCDEF b) 12 BCDEF 12 d) ABCDEF 36 BCDEFF c) 24 445. Which method determines the specified 24 character is an uppercase character. 36 6 a) isUpperCase(char) d) 12 b) isUpperCase() 24 c) toUpperCase(char) d) isUpperCase() c) Boolean & False d) boolean & false 446. Which unit of the class gets executed at 453. State the number of bytes occupied by the time of instantiation? char and int data types. a) Method a) char-1 bytes & int-4 bytes b) Constructor b) char-2 bytes & int-8 bytes c) Object c) char-2 bytes & int-8 bytes d) Package d) char-2 bytes & int-4 bytes 454. Arrange the following primitive data 447. The prototype of a function check which types in ascending order of their size: receives a character ch and an integer n and char, byte, double, int returns true or false. a) int, char, byte, double a) true check(char ch, int n) b) byte, char, int, double b) false check(char ch, int n) c) char, int, byte, double c) boolean check(char ch, int n) d) double, int, char, byte d) Boolean check(char ch, int n) 455.Given array int x[] = {11, 22, 33, 44}; 448. Which method converts a string to a the value of x[1+2] is ........... . primitive float data type. a)11 a) float.parsefloat() b)22 b) float.parseFloat() c)33 c) Float.parsefloat() d)44 d) Float.parseFloat() 456. What is an Array in Java? 449. _________________ are the constructors a) A collection of elements with different types with at least one parameter and initialize b) A collection of elements with the same type instance variable with received values c) A resizable data structure a) Parameterized Constructor d) A container for storing key-value pairs b) Non-Parameterized Constructor 457. Out of these statements, which ones are c) Default Constructor incorrect? d) Both (i) & (ii) a. The Brackets () have the highest precedence 450. Evaluate the following expression if the b. The equal to = operator has the lowest value of x = 2, y = 3 and z = 1. precedence v = x + --z + y++ + y; c. The addition operator + and the subtraction a) 9 operator – have an equal precedence b) -9 d. The division operator / has comparatively c) 19 higher precedence as compared to a d) 29 multiplication operator 451. What is the result stored in x, after Ans: (d) The division operator / has evaluating the following expression? comparatively higher precedence as compared int x = 5; x = x++ * 2 + 3 * --x; 8 to a multiplication operator a) 24 458. When does Overloading not occur? b) 25 a. When more than a single method have the c) 26 same name, yet different types or number of d) 27 parameters and different method signature 452. State the data type and value of res after b. When more than a single method have the the following is executed: same name, the same signature, but have char ch = '9'; different numbers of signature res = Character.isDigit(ch); c. When more than a single method have the a) Boolean & True same signature, same name, and the same b) boolean & true number of parameters have different types d. When more than a single method have the d) An array uses a zero index to reference the same name, the same number and types of first element. parameters, and yet different signatures 465.What will be the output of the program? Ans: (d) When more than a single method have class Main the same name, the same number and types { of parameters, and yet different signatures public static void main() 459. When does the { ArrayIndexOutOfBoundsException occur? int arr[] = {10, 20, 30, 40, 50}; a) Compile-time for(int i=0; i < arr.length; i++) b) Run-time System.out.print(" " + arr[i]); c) Not an error } d) Not an exception at all } 460. What is the index range for the elements a) 10 20 30 40 50 of an array in Java? b) Compiler Error a) 0 to length - 1 c) 10 20 30 40 b) 1 to length d) None of the above c) -1 to length - 1 465. What will be the output of the program? d) 0 to length int array_variable [] = new int[10]; 461. Can the length of an array be changed for (int i = 0; i < 10; ++i) after its creation in Java? { a) Yes, by using the resize() method array_variable[i] = i; b) Yes, by using the length property System.out.print(array_variable[i] + " "); c) No, the length of an array is fixed after i++; creation } d) No, arrays in Java have a fixed length a) 0 2 4 6 8 462. Which of the following creates an empty b) 1 3 5 7 9 two-dimensional array with dimensions 2×2? c) 0 1 2 3 4 5 6 7 8 9 a) int[][] blue = new int[2, 2]; d) 1 2 3 4 5 6 7 8 9 10 b) int[][] blue = new int[2], [2]; Ans : A c) int[][] blue = new int[2][2]; 466. What will be output for the following d) int[][] blue = new int[2 x 2]; code? 463. How many of the following are legal int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; declarations? int n = 6; float[] lion = new float[]; n = arr[arr[n] / 2]; float[] tiger = new float[1]; System.out.print(n); float[] bear = new[] float; a) 3 float[] cat = new[1] float; b) 0 a) None c) 6 b) One d) 1 c) Two Ans : A d) Three 467. Which of the following best describes an 464. Which is not a true statement about an array in Java? array? a) An array is a data structure that can store a) An array expands automatically when it is multiple values of different data types full. sequentially. b) An array is allowed to contain duplicate b) An array is a method in the Java standard values. library used to manipulate data. c) An array understands the concept of ordered elements. c) An array is a data structure that can store b. 10 5 12 10 multiple values of the same data type c. 5 10 12 8 sequentially. d. None of these d) An array is a keyword in Java used for Ans- (b) 10 5 12 10 conditional checks. 472. If an array ―tarr‖ is created as int tarr*+ = 468. Which of the following statements new tarr[10]; What will be the contents of correctly declares a two-dimensional integer tarr[6] array? a. 0 a) int[][] a = new int; b. 1 b) int[][] a = new int; c. Void c) int[][] a = { {1, 2, 3}, {4, 5, 6} }; d. NULL d) int[][] a = {1, 2, 3}, {4, 5, 6}; Ans- (a) 21.From the given array y[][] = {{3,4,5}, {6,7,8},{1,2,3}};The element at y[2][2] is : a. 1 b. 2 c. 3 d. 4 Ans – ( c ) 3 469. Write a set of statements that would find and print the size of array. ar[] = {2,5,6,7,8,9,10}; a. Int len = ar.length; System.out.println(―The size of array =‖+len); b. int len = ar.length(); System.out.println(―The size of array =‖+len ); c. int len = ar.len; System.out.println(―The size of array =‖+len); d. None of these Ans – (a) 470. Which of the following is advantage of Java array? a. Code Optimization b. Random access c. Unlimited size d. Both a and b above Ans- (b) Random Access 471. In Java, array elements are stored in …………… memory locations. a. Random b. Sequential c. Sequential Random d. Stacked Ans- ( c ) Sequential 471. What is printed by the below statements? int num[] = {3,5,10,12,18}; System.out.println(num*2++‖\t‖+num*1++‖\t‖ +num[3]+‖\t‖+num*4-2]); a. 3 5 10 12