0
Alien head

Select the output of Java Program

Description: You will be given sample program or statement, Select appropriate output or statement from the given option
Number of Questions: 20
Created by:
Tags: java programming language
Attempted 0/20 Correct 0 Score 0
int x = 12;  
while (x < 10) {  
   x--;  
}  
System.out.print(x); 

What is the result?

  1. 0

  2. 10

  3. 12

  4. print statement never be executed


Correct Option: C
public class CreditCard {  
  private String cardID;  
  private Integer limit;  
  public String ownerName;
  public void setCardInformation(String cardID,  String ownerName,  Integer limit) {  
  this.cardID = cardID;  
  this.ownerName = ownerName;
  this.limit = limit; 
 }  
}    

Which statement is true?

  1. The class is fully encapsulated

  2. The code demonstrates polymorphism

  3. The ownerName variable breaks encapsulation

  4. The cardID and limit variables break polymorphism


Correct Option: C
String[] elements = { "for", "tea", "too" }; 
String first = (elements.length > 0) ? elements[0] : null;    

What is the result?

  1. Compilation fails

  2. An exception is thrown at runtime

  3. The variable first is set to null

  4. The variable first is set to elements[0]


Correct Option: D
public static void main(String[] args) {
  String str = "null"; 
 if (str == null) {
  System.out.println("null");
  } else (str.length() == 0) {
  System.out.println("zero");
  } else {
  System.out.println("some");
  }  
}    

What is the result?

  1. null

  2. zero

  3. some

  4. Compilation fails


Correct Option: D
public class Yippee2 {
  static public void main(String [] yahoo) {
  for(int x = 1; x < yahoo.length; x++) {
  System.out.print(yahoo[x] + " ");
  }
 }
}

and the command line invocation: java Yippee2 a b c What is the result?

  1. a b

  2. b c

  3. a b c

  4. Compilation fails


Correct Option: B
NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(4);
nf.setMinimumFractionDigits(2);  
String a = nf.format(3.1415926);
String b = nf.format(2);

Which statement is true about the result?

  1. The value of b is 2

  2. The value of b is 2.00

  3. The value of a is 3.1415

  4. The value of a is 3.141


Correct Option: B

System.out.format("Pi is approximately %d.", Math.PI);
What is the result?

  1. Compilation fails

  2. Pi is approximately 3

  3. Pi is approximately 3.141593

  4. An exception is thrown at runtime


Correct Option: D
int x = 12;
while (x < 10) {
    x--;  
}  
System.out.print(x);

What is the result?

  1. 0

  2. 10

  3. 12

  4. print statement never be executed


Correct Option: C
public class CreditCard {
 private String cardID;
 private Integer limit;
 public String ownerName;
 public void setCardInformation(String cardID, String ownerName, Integer limit) {
  this.cardID = cardID;
  this.ownerName = ownerName;
  this.limit = limit;
 }
}

Which statement is true?

  1. The class is fully encapsulated

  2. The code demonstrates polymorphism

  3. The ownerName variable breaks encapsulation

  4. The cardID and limit variables break polymorphism


Correct Option: C
String[] elements = {
 "for",
 "tea",
 "too"
};
String first = (elements.length > 0) ? elements[0] : null;

What is the result?

  1. Compilation fails

  2. An exception is thrown at runtime

  3. The variable first is set to null

  4. The variable first is set to elements[0]


Correct Option: D
public static void main(String[] args) {
 Integer i = new Integer(1) + new Integer(2);
 switch (i) {
  case 3:
   System.out.println("three");
   break;
  default:
   System.out.println("other");
   break;
 }
}

What is the output?

  1. three

  2. other

  3. Compilation Fails

  4. Exception


Correct Option: A
int x = 0;
int y = 10;
do {
 y--;
 ++x;
} while (x < 5);
System.out.print(x + "," + y);

What is the result?

  1. 5,6

  2. 5,5

  3. 6,5

  4. 6,6


Correct Option: B
int x = 10;
do {
 x--;
} while (x < 10);

How many times the loop will be executed?

  1. ten times

  2. zero times

  3. one to nine times

  4. more than ten times


Correct Option: D

String name="ALIEN";
name.reverse();


Is code successfully compiled..???

  1. True

  2. False


Correct Option: B

By default type of variable(data members) in interface..???

  1. public,final

  2. Only Final

  3. Only Public

  4. public,final,static


Correct Option: D

clone method used for..???

  1. Used for Cloning or copying integer var

  2. Used for Cloning or copying float var

  3. Used for Cloning or copying String var

  4. Used for Cloning an array


Correct Option: D

Is typecasting is allowed between two different objects of different classes???

  1. True

  2. False


Correct Option: B

Is Multiple Inheritance allowed in JAVA???

  1. True

  2. False


Correct Option: B

interface <interface name> extends <interface name1>Is correct???

  1. True

  2. False


Correct Option: A

Syntax of System.arraycopy method??

  1. System.arraycopy(fromarray,frominden,toarray,toindex,count);

  2. System.arraycopy(toarray,toinden,fromarray,fromindex,count);

  3. System.arraycopy(fromarray,toarray,count);

  4. System.arraycopy();


Correct Option: A
+ View questions