Tag: programming languages

Questions Related to programming languages

Given: 11. public static void test(String str) { 12. int check = 4; 13. if (check = str.length()) { 14. System.out.print(str.charAt(check -= 1) +“, “); 15. } else { 16. System.out.print(str.charAt(0) + “, “); 17. } 18. } and the invocation: 21. test(”four”); 22. test(”tee”); 23. test(”to”); What is the result?

  1. r, t, t,

  2. r, e, o,

  3. Compilation fails.

  4. An exception is thrown at runtime.


Correct Option: C

Given: 11. public static void test(String str) { 12. int check = 4; 13. if (check = str.length()) { 14. System.out.print(str.charAt(check -= 1) +“, “); 15. } else { 16. System.out.print(str.charAt(0) + “, “); 17. } 18. } and the invocation: 21. test(”four”); 22. test(”tee”); 23. test(”to”); What is the result?

  1. r, t, t,

  2. r, e, o,

  3. Compilation fails.

  4. An exception is thrown at runtime.


Correct Option: C

A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command: java games.cards.Poker What allows the user to do this? A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/.jar C. Put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar D. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuffijava/.jar F. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/Poker.jar

  1. A

  2. B

  3. C

  4. D

  5. E

  6. F


Correct Option: C

What is the result of compiling and running this program? class Clove{ void quality(Clove m){ System.out.println("Clove is nice"); } } class Mint extends Clove{ void quality(Mint c){ System.out.println("Mint is ok"); } } class Sage extends Mint{ void quality(Sage h){ System.out.println("Sage is average"); } } public class Test{ public static void main(String[] args){ Clove h = new Sage(); Mint c = new Sage(); c.quality(h); } }

  1. prints "Clove is nice"

  2. prints "Mint is ok"

  3. prints "Sage is average"

  4. Class cast Exception at runtime.


Correct Option: A

Given classes defined in two different files: 1. package util; 2. public class BitUtils { 3. private static void process(byte[] b) { } 4. } 1. package app; 2. public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils?

  1. process(bytes);

  2. BitUtils.process(bytes);

  3. app.BitUtils.process(bytes);

  4. util.BitUtils.process(bytes);

  5. import util.BitUtils. *; process(bytes);

  6. SomeApp cannot use the process method in BitUtils.


Correct Option: F

Given classes defined in two different files: 1. package util; 2. public class BitUtils { 3. public static void process(byte[]) { /* more code here */ } 4. } 1. package app; 2. public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils?

  1. process(bytes);

  2. BitUtils.process(bytes);

  3. util.BitUtils.process(bytes);

  4. SomeApp cannot use methods in BitUtils.

  5. import util.BitUtils.*; process(bytes);


Correct Option: C

Given: 11. // insert code here 12. private N min, max; 13. public N getMin() { return min; } 14. public N getMax() { return max; } 15. public void add(N added) { 16. if (min == null || added.doubleValue() max.doubleValue()) 19. max = added; 20. } 21. } Which two, inserted at line 11, will allow the code to compile? (Choose two.)

  1. public class MinMax> {

  2. public class MinMax extends Number> {

  3. public class MinMax {

  4. public class MinMax {

  5. public class MinMax extends Object> {

  6. public class MinMax {


Correct Option: D,F