Java Programming Fundamentals
Test your knowledge of Java programming including control structures, OOP concepts, API usage, and syntax
Questions
Syntax of System.arraycopy method??
- System.arraycopy(fromarray,frominden,toarray,toindex,count);
- System.arraycopy(toarray,toinden,fromarray,fromindex,count);
- System.arraycopy(fromarray,toarray,count);
- System.arraycopy();
interface <interface name> extends <interface name1>Is correct???
- True
- False
Is Multiple Inheritance allowed in JAVA???
- True
- False
Is typecasting is allowed between two different objects of different classes???
- True
- False
clone method used for..???
- Used for Cloning or copying integer var
- Used for Cloning or copying float var
- Used for Cloning or copying String var
- Used for Cloning an array
By default type of variable(data members) in interface..???
- public,final
- Only Final
- Only Public
- public,final,static
String name="ALIEN"; name.reverse();
Is code successfully compiled..???
- True
- False
int x = 10;
do {
x--;
} while (x < 10);
How many times the loop will be executed?
- ten times
- zero times
- one to nine times
- more than ten times
int x = 0;
int y = 10;
do {
y--;
++x;
} while (x < 5);
System.out.print(x + "," + y);
What is the result?
- 5,6
- 5,5
- 6,5
- 6,6
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?
- three
- other
- Compilation Fails
- Exception
String[] elements = {
"for",
"tea",
"too"
};
String first = (elements.length > 0) ? elements[0] : null;
What is the result?
- Compilation fails
- An exception is thrown at runtime
- The variable first is set to null
- The variable first is set to elements[0]
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?
- The class is fully encapsulated
- The code demonstrates polymorphism
- The ownerName variable breaks encapsulation
- The cardID and limit variables break polymorphism
int x = 12;
while (x < 10) {
x--;
}
System.out.print(x);
What is the result?
- 0
- 10
- 12
- print statement never be executed
System.out.format("Pi is approximately %d.", Math.PI);
What is the result?
- Compilation fails
- Pi is approximately 3
- Pi is approximately 3.141593
- An exception is thrown at runtime
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?
- The value of b is 2
- The value of b is 2.00
- The value of a is 3.1415
- The value of a is 3.141
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?
- a b
- b c
- a b c
- Compilation fails
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?
- null
- zero
- some
- Compilation fails
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0) ? elements[0] : null;
What is the result?
- Compilation fails
- An exception is thrown at runtime
- The variable first is set to null
- The variable first is set to elements[0]
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?
- The class is fully encapsulated
- The code demonstrates polymorphism
- The ownerName variable breaks encapsulation
- The cardID and limit variables break polymorphism
int x = 12;
while (x < 10) {
x--;
}
System.out.print(x);
What is the result?
- 0
- 10
- 12
- print statement never be executed