String shirts[][] = new String[2][2]; shirts[0][0]="red"; shirts[0][1]="blue"; shirts[1][0]="small"; shirts[1][1]="medium";
Which code fragment prints red: blue: small: medium?
1. A
2. B 3. C
4. D
Correct Answer : 4
Explanation: Yes, we need embeded for loop. In first iteration of outerloop, inner loop will iterate twice and print the data from same row. In this case it will be red : blue and in next iteration it will print all the values from second row and will print small:medium . Hence, option 4 is correct.
Question :
A. this.amount = 0; B. amount = 0; C. acct (0) ; D. acct.amount = 0; E. acct. getAmount () = 0; F. acct.changeAmount(0); G. acct.changeAmount(-acct.amount); H. acct.changeAmount(-acct.getAmount());
1. A,B,C 2. A,C,D 3. D,G,H 4. E,F,G 5. A,E,F
Correct Answer : 3
Explanation: In option D, we are explicitely setting the amount value as 0 and remaining and in option G and H we are passing the same amount with the negation. Hence, it will make this amount to 0.
Question : Given the code fragment from three files: Which code fragment, when inserted at line 2 (in third file), enables the code to compile?
package sales; public class SalesMan { }
package sales.products; public class Product { }
package market; //insert code here public class USMarket { SalesMan sm; Product p; } 1. import sales.*;
Explanation: You have to import a class explicitely or entire package. In the given option we are not importing classes explicitley. Hence, we need to import entire package and in option 4 we are doing this.