Java Programming Fundamentals

Test your knowledge of Java programming including control structures, OOP concepts, API usage, and syntax

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

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();
Question 2 True/False

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

  1. True
  2. False
Question 3 True/False

Is Multiple Inheritance allowed in JAVA???

  1. True
  2. False
Question 4 True/False

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

  1. True
  2. False
Question 5 Multiple Choice (Single Answer)

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
Question 6 Multiple Choice (Single Answer)

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

  1. public,final
  2. Only Final
  3. Only Public
  4. public,final,static
Question 7 True/False

String name="ALIEN"; name.reverse();
Is code successfully compiled..???

  1. True
  2. False
Question 8 Multiple Choice (Single Answer)
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
Question 9 Multiple Choice (Single Answer)
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
Question 10 Multiple Choice (Single Answer)
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
Question 11 Multiple Choice (Single Answer)
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]
Question 12 Multiple Choice (Single Answer)
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
Question 13 Multiple Choice (Single Answer)
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
Question 14 Multiple Choice (Single Answer)

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
Question 15 Multiple Choice (Single Answer)
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
Question 16 Multiple Choice (Single Answer)
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
Question 17 Multiple Choice (Single Answer)
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
Question 18 Multiple Choice (Single Answer)
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]
Question 19 Multiple Choice (Single Answer)
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
Question 20 Multiple Choice (Single Answer)
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