0

programming languages Online Quiz - 21

Description: programming languages Online Quiz - 21
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

By using which method ,How can one increase size of an ArrayList?

  1. incSize(int minCapacity)

  2. ensureCapacity(int minCapacity)

  3. incCapicity(int minCapacity)

  4. All of the Above


Correct Option: B

what a Clone method returns in ArrayList?

  1. Returns String

  2. Returns an Array

  3. Returns a shallow copy of this ArrayList instance

  4. Returns Void


Correct Option: C

Is Abstract Class is Parent Class of ArrayList?

  1. True

  2. False


Correct Option: A

Python lists are mutable

  1. True

  2. False


Correct Option: A

name=[1]*3

  1. [11]

  2. syntax error

  3. [1,1,1]

  4. runtime error


Correct Option: C

a=['a','b'] x=[a,'y']

  1. x[0][0]

  2. Syntax error at line 1

  3. Syntax error at line 2

  4. runtime error


Correct Option: A

x=[1,2,3,4,5] print x[-1]

  1. error

  2. 5

  3. garbage number

  4. 3


Correct Option: B

x=[1,2,3,4,5] x[3:3]='sagar' print x

  1. error

  2. [1,2,3,4,'sagar',5]

  3. [1,2,3,'sagar']

  4. none


Correct Option: B

If you run the code below, what gets printed out? String s=new String("Bicycle"); int iBegin=1; char iEnd=3; System.out.println(s.substring(iBegin,iEnd));

  1. Bic

  2. ic

  3. icy

  4. error: no method matching substring(int,char)


Correct Option: B

What does the following paint( ) method draw?

  1. A circle at (100, 100) with radius of 44

  2. A circle at (100, 44) with radius of 100

  3. A circle at (100, 44) with radius of 44

  4. The code does not compile


Correct Option: D

AI Explanation

To answer this question, we need to analyze the given paint() method.

Since we don't have the actual code for the paint() method, we can't determine the exact output. However, based on the given options, we can deduce that the correct answer is D - "The code does not compile."

This is because none of the provided options match the given method signature, which suggests that the code may be incomplete or incorrect.

Without further information or code, it is not possible to determine the specific shape or object that the paint() method would draw. Therefore, the correct answer is D.

  1. When you construct an instance of File, if you do not use the filenaming semantics of the local machine, the constructor will throw an IOException.

  2. When you construct an instance of File, if the corresponding file does not exist on the local file system, one will be created.

  3. When an instance of File is garbage collected, the corresponding file on the local file system is deleted.

  4. None of the above.


Correct Option: A,B,C

Which of these are not legal identifiers. Select all the correct answers.

  1. 1alpha

  2. _abcd

  3. xy+abc

  4. transient

  5. account-num

  6. very_long_name


Correct Option: A,C,D,E

AI Explanation

To answer this question, we need to understand the rules for legal identifiers in programming languages.

In general, legal identifiers must follow these rules:

  1. They can only contain letters (both uppercase and lowercase), digits, and underscores.
  2. They cannot start with a digit.
  3. They cannot contain special characters such as +, -, *, /, etc.

Let's go through each option to determine which ones are not legal identifiers:

A. 1alpha - This option is not a legal identifier because it starts with a digit.

B. _abcd - This option is a legal identifier because it starts with an underscore and contains only letters, digits, and underscores.

C. xy+abc - This option is not a legal identifier because it contains the special character '+'.

D. transient - This option is a legal identifier because it contains only letters.

E. account-num - This option is not a legal identifier because it contains the hyphen '-'.

F. very_long_name - This option is a legal identifier because it contains only letters, and underscores.

Therefore, the correct answers are A, C, D, and E.

What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer. public static ShortCkt { public static void main(String args[]) { int i = 0; boolean t = true; boolean f = false, b; b = (t && ((i++) == 0)); b = (f && ((i+=2) > 0)); System.out.println(i); } }

  1. 0

  2. 1

  3. 2

  4. 3


Correct Option: B

Is it possible to have a virtual destructor?

  1. True

  2. False


Correct Option: A

interface my_interface{ public void show(); } public class test08 { public static void main(String[] args) { my_interface mi = new B(); mi.show(); } } class A implements my_interface{ public void show(){ System.out.println("This is implemented method "); } } class B extends A{ public void show(){ System.out.println("This is overrided method "); } } What is the output

  1. This is implemented method

  2. This is overrided method

  3. Compile time Error

  4. Run time error


Correct Option: B

By default any class would be supplied with?

  1. Constructor

  2. Destructor

  3. Overloaded assignment operator

  4. Default Copy Constructor


Correct Option: A,B,C,D

public class Change { public static void main(String args[]) { System.out.println(2.00 - 1.10); } } What is the output

  1. 0.9

  2. 0.90

  3. It varies

  4. None of the above


Correct Option: D

AI Explanation

To answer this question, let's analyze the given code.

The code snippet calculates the difference between 2.00 and 1.10 and prints the result using the System.out.println() method.

In Java, floating-point numbers are represented using the double data type. However, due to the way floating-point numbers are stored in memory, they may not always have an exact representation.

When we subtract 1.10 from 2.00, we would expect the result to be 0.90. However, due to the imprecise nature of floating-point arithmetic, the actual result may not be exactly 0.90.

Let's check the options:

Option A) 0.9 - This option is incorrect because the actual result may not be exactly 0.9.

Option B) 0.90 - This option is incorrect for the same reason as Option A.

Option C) It varies - This option is correct. The output of the code can vary depending on the platform and the floating-point representation used.

Option D) None of the above - This option is correct. The output of the code will not be exactly 0.9 or 0.90, and it can vary.

Therefore, the correct answer is Option D.

public class test08 { public static void main(String[] args) { final int start = Integer.MAX_VALUE - 100; final int end = Integer.MAX_VALUE; int count = 0; for (int i = start; i <= end; i++) count++; System.out.println(count); } } What will be the output

  1. 100

  2. 101

  3. 102

  4. None of the above


Correct Option: D

AI Explanation

To determine the output of the given code, let's go through the code step by step:

  1. The variable start is initialized with the value Integer.MAX_VALUE - 100, which is the maximum value that an int variable can hold minus 100.
  2. The variable end is initialized with the value Integer.MAX_VALUE, which is the maximum value that an int variable can hold.
  3. The variable count is initialized with the value 0.
  4. A for loop is used to iterate from start to end, inclusive. Since start is already set to Integer.MAX_VALUE - 100, the loop will execute 201 times (from start to start + 200).
  5. In each iteration, the count variable is incremented by 1.
  6. After the loop finishes, the value of count is printed.

Now, let's analyze the options:

Option A) 100 - This option implies that the loop will iterate exactly 100 times. However, as mentioned earlier, the loop will iterate 201 times.

Option B) 101 - This option implies that the loop will iterate exactly 101 times. However, as mentioned earlier, the loop will iterate 201 times.

Option C) 102 - This option implies that the loop will iterate exactly 102 times. However, as mentioned earlier, the loop will iterate 201 times.

Option D) None of the above - This option is correct because the loop will iterate 201 times, not any of the given options (A, B, or C).

Therefore, the correct answer is D) None of the above.

class A{ public void show(){ System.out.println("This is A"); } class B extends A{ protected void show(){ System.out.println("This is B"); } public class Main{ public static void main(String[] args) { A a = new B(); a.show(); } } What is the output

  1. This is A

  2. This is B

  3. Nothing will be printed as output

  4. None of the above


Correct Option: D

AI Explanation

To answer this question, let's go through the code step by step:

  1. There are two classes defined: class A and class B.
  2. Class A has a method called show() which prints "This is A".
  3. Class B extends class A and overrides the show() method to print "This is B".
  4. Inside the class Main, the main() method is defined.
  5. In the main() method, an object a of type A is created and assigned a new instance of class B using the statement A a = new B();.
  6. The show() method is called on the object a.
  7. Since the object a is of type A, but refers to an instance of class B, polymorphism comes into play.
  8. The method show() that gets executed is the overridden method in class B, which prints "This is B".

Therefore, the correct answer is:

D. None of the above

public class test08 { public static void main(String[] args) { System.out.print("H" + "a"); System.out.print('H' + 'a'); } } What is the output?

  1. HaHa

  2. Ha

  3. Compile error

  4. None of the above


Correct Option: D

AI Explanation

To answer this question, let's go through each option and analyze the code:

Option A) HaHa - This option is incorrect. Let's analyze the code to understand why. In the first line of the main method, the statement System.out.print("H" + "a"); concatenates the strings "H" and "a", resulting in "Ha". Therefore, "Ha" will be printed.

Option B) Ha - This option is incorrect. As explained above, the code will print "Ha", not "HaHa".

Option C) Compile error - This option is incorrect. The code does not contain any errors, so it will compile successfully.

Option D) None of the above - This option is correct. The code will print "Ha" for the first statement, but the second statement System.out.print('H' + 'a'); will have a different behavior. In this case, the characters 'H' and 'a' are treated as integers due to the use of the '+' operator. The ASCII values of 'H' and 'a' are 72 and 97, respectively. Therefore, the expression 'H' + 'a' is equivalent to 72 + 97, which equals 169. As a result, the output will be the character corresponding to the ASCII value 169, which may vary depending on the system's character encoding.

Therefore, the correct answer is D) None of the above.

- Hide questions