0

programming languages Online Quiz - 336

Description: programming languages Online Quiz - 336
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0
  1. itemMap.remove("orange"); itemMap.put("orange", new Item("Orange") );

  2. ((Item)itemMap.get(“orange”)).name = “Orange”;

  3. itemMap.put("orange", new Item("Orange") );

  4. None of above


Correct Option: B

Which is the most performance efficient implementation for assignCode method from the given options?

  1. code attribute cannot be changed as Item class doesn’t have setter method for it.

  2. for (int i = 0; i < itemList.size(); i++) { if(itemList.get(i) != null) { ((Item)itemList.get(i)).code = 50+i; } }

  3. int i = 0; Item im = null; while (i < itemList.size()) { im = (Item)itemList.get(i); if(im != null) { im.code = 50+i; } i++; }

  4. int i = 0; Item im = null; Iterator itr = itemList.iterator(); while (itr.hasNext()) { im =(Item) itr.next(); im.code = 50+i; i++; }


Correct Option: D
  1. Item im = new Item(null); im = (Item ) itemList.get(0);

  2. Item im = new Item(“Done”); im = (Item ) itemList.get(0);

  3. Item im = null; im = (Item ) itemList.get(0);

  4. All of the above.


Correct Option: C

Which code in the given options if put in below Main class will not print “Done”?

  1. Function call:- changeName(im); Function implementation :- { im.name = "Done"; return null; }

  2. Function call:- changeName(im); Function implementation :- { im = new Item("Done"); return null; }

  3. Function call :- im = changeName(im); function implementation :- { Item otherObject = new Item("Done"); return otherObject; }

  4. All of the above


Correct Option: B

Which code from the given options if put in Main class will not print “Done”?

  1. Function call:- changeName(im); Function implementation :- { im.name = "Done"; return null; }

  2. Function call:- changeName(im); Function implementation :- { im = new Item("Done"); return null; }

  3. Function call :- im = changeName(im); function implementation :- { Item otherObject = new Item("Done"); return otherObject; }

  4. All of the above


Correct Option: B

Which is simplest code snippet you will add in the main function to set the name attribute of 50th in the ItemList to “Done”?

  1. im.name = "Done";

  2. Item otherObject = new Item(“Done”); itemList.set(49, otherObject);

  3. ((Item)itemList.get(49)).name = “Done”;

  4. None of above is correct as they are not changing 50th element.


Correct Option: A

Which of the given options code is correct and will not waste memory. Note :- Defination of the Class Item is class Item { public int code; public String name; public Item(String name) { this.name = name; } } itemList is ArrayList containing 50 objects of Class Items.

  1. Item im = new Item(null); im = (Item ) itemList.get(0);

  2. Item im = new Item(“Done”); im = (Item ) itemList.get(0);

  3. Item im = null; im = (Item ) itemList.get(0);

  4. All of the above.


Correct Option: C
  1. itemMap.remove("orange"); itemMap.put("orange", new Item("Orange") );

  2. ((Item)itemMap.get(“orange”)).name = “Orange”;

  3. itemMap.put("orange", new Item("Orange") );

  4. None of above


Correct Option: B
  1. code attribute cannot be changed as Item class doesn’t have setter method for it.

  2. for (int i = 0; i < itemList.size(); i++) { if(itemList.get(i) != null) { ((Item)itemList.get(i)).code = 50+i; } }

  3. int i = 0; Item im = null; while (i < itemList.size()) { im = (Item)itemList.get(i); if(im != null) { im.code = 50+i; } i++; }

  4. int i = 0; Item im = null; Iterator itr = itemList.iterator(); while (itr.hasNext()) { im =(Item) itr.next(); im.code = 50+i; i++; }


Correct Option: D

Which is simplest and correct code snippet needs to be put in the main function to replace the value object of the HashMap for the key “orange”?

  1. itemMap.remove("orange"); itemMap.put("orange", new Item("Orange") );

  2. ((Item)itemMap.get(“orange”)).name = “Orange”;

  3. itemMap.put("orange", new Item("Orange") );

  4. None of above


Correct Option: B

Which is the most performance efficient implementation for assignCode method from the given options?

  1. code attribute cannot be changed as Item class doesn’t have setter method for it.

  2. for (int i = 0; i < itemList.size(); i++) { if(itemList.get(i) != null) { ((Item)itemList.get(i)).code = 50+i; } }

  3. int i = 0; Item im = null; while (i < itemList.size()) { im = (Item)itemList.get(i); if(im != null) { im.code = 50+i; } i++; }

  4. int i = 0; Item im = null; Iterator itr = itemList.iterator(); while (itr.hasNext()) { im =(Item) itr.next(); im.code = 50+i; i++; }


Correct Option: D

Which code from the given options if put in Main class will not print “Done”?

  1. Function call:- changeName(im); Function implementation :- { im.name = "Done"; return null; }

  2. Function call:- changeName(im); Function implementation :- { im = new Item("Done"); return null; }

  3. Function call :- im = changeName(im); function implementation :- { Item otherObject = new Item("Done"); return otherObject; }

  4. All of the above


Correct Option: B
  1. im.name = "Done";

  2. Item otherObject = new Item(“Done”); itemList.set(49, otherObject);

  3. ((Item)itemList.get(49)).name = “Done”;

  4. None of above is correct as they are not changing 50th element.


Correct Option: A

Which of the given options code is correct and will not waste memory. Note :- Defination of the Class Item is class Item { public int code; public String name; public Item(String name) { this.name = name; } } itemList is ArrayList containing 50 objects of Class Items.

  1. Item im = new Item(null); im = (Item ) itemList.get(0);

  2. Item im = new Item(“Done”); im = (Item ) itemList.get(0);

  3. Item im = null; im = (Item ) itemList.get(0);

  4. All of the above.


Correct Option: C

Examine this package body: CREATE OR REPLACE PACKAGE BODY forward_pack IS V_sum NUMBER; - 44 - PROCEDURE calc_ord(. . . ); PROCEDURE generate_summary(. . . ) IS BEGIN Calc_ord(. . . ); . . . END calc_ord; END forward_pack; / Which construct has a forward declaration?

  1. a) V_SUM

  2. b) CALC_ORD.

  3. c) FORWARD_PACK

  4. d) GENERATE_SUMMARY.


Correct Option: B

which is the value of x and y after running this code? class a { public static void main(String args[]) { int x=1; int y=x++; } }

  1. x=1 and y=1

  2. x=1 and y=2

  3. x=2 and y=2

  4. x=2 and y=1


Correct Option: D

What is the output:class a { public static void main (String args[]) { int x; int y=10; if (y>0) { x = 10; } System.out.println(x); } }

  1. 10

  2. 0

  3. Garbage Value

  4. Compile time error


Correct Option: D
- Hide questions