class Craven{
Craven(){
System.out.println("Craven");
}
}
public class CilDig extends Craven{
public static void main(String argv[]){
CilDig _c = new CilDig();
}
public CilDig(){
System.out.println("CilDig");
}
}
1Compile time error, an object reference cannot start with underscore
2 Compilation and output of "CilDig"
3 Compilation and output of "Craven" followed by "CilDig"
4 Compile time error, method CilDig has no return type
OOPS.................
Saturday, January 3, 2009
What will happen when you attempt to compile and run the following code?
class Craven{
Craven(){
System.out.println("Craven");
}
}
public class CilDig extends Craven{
public static void main(String argv[]){
CilDig _c = new CilDig();
}
public CilDig(){
System.out.println("CilDig");
}
}
Answers:
1:Compile time error, an object reference cannot start with underscore
2:Compilation and output of "CilDig"
3: Compilation and output of "Craven" followed by "CilDig"
4: Compile time error, method CilDig has no return type
Craven(){
System.out.println("Craven");
}
}
public class CilDig extends Craven{
public static void main(String argv[]){
CilDig _c = new CilDig();
}
public CilDig(){
System.out.println("CilDig");
}
}
Answers:
1:Compile time error, an object reference cannot start with underscore
2:Compilation and output of "CilDig"
3: Compilation and output of "Craven" followed by "CilDig"
4: Compile time error, method CilDig has no return type
Friday, January 2, 2009
What will happen when you attempt to compile and run the following code?
import java.util.*;
public class Scan{
public static void main(String argv[]){
new Scan();
}
Scan(){
String input = "Richard,Libby,Hattie,Alice";
Scanner scan = new Scanner(input).useDelimiter(",");
while(scan.hasNext()){
System.out.print(scan.next());
}
}
}
Answers:
1:Compile time error, Scanner has no useDelimiter method.
2:Compilation and output of "Richard,Libby,Hattie,Alice"
3:Compilation but no output at runtime.
4:Compilation and output of "RichardLibbyHattieAlice"
public class Scan{
public static void main(String argv[]){
new Scan();
}
Scan(){
String input = "Richard,Libby,Hattie,Alice";
Scanner scan = new Scanner(input).useDelimiter(",");
while(scan.hasNext()){
System.out.print(scan.next());
}
}
}
Answers:
1:Compile time error, Scanner has no useDelimiter method.
2:Compilation and output of "Richard,Libby,Hattie,Alice"
3:Compilation but no output at runtime.
4:Compilation and output of "RichardLibbyHattieAlice"
Thursday, January 1, 2009
What will happen when you attempt to compile and run the following code?
import java.util.*;
public class VecOrder{
public static void main(String argv[]){
new VecOrder();
}
VecOrder(){
Vector child = new Vector();
child.add("harry");
child.add("molly");
child.add("steven");
child.add("helen");
Collections.sort(child);
for(String element : child){
System.out.print(element);
}
}
}
Answers:...........
1 :Compilation error, problem with creation of instance of Vector class
2 :Compilation but runtime error, the Collections.sort method can only sort objects of type List
3:Compilation error, the for loop structure needs to cast each element of the Vector array to a String
4:Compilation and output of harryhelenmollysteven
public class VecOrder{
public static void main(String argv[]){
new VecOrder();
}
VecOrder(){
Vector
child.add("harry");
child.add("molly");
child.add("steven");
child.add("helen");
Collections.sort(child);
for(String element : child){
System.out.print(element);
}
}
}
Answers:...........
1 :Compilation error, problem with creation of instance of Vector class
2 :Compilation but runtime error, the Collections.sort method can only sort objects of type List
3:Compilation error, the for loop structure needs to cast each element of the Vector array to a String
4:Compilation and output of harryhelenmollysteven
Wednesday, December 31, 2008
You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it.?
public class MyAr{
public static void main(String argv[]){
int[] i = new int[5];
System.out.println(i[5]);
}
}
1 an error at compile time
2 an error at runtime
3 The value 0 will be output
4 The string "null" will be output
public static void main(String argv[]){
int[] i = new int[5];
System.out.println(i[5]);
}
}
1 an error at compile time
2 an error at runtime
3 The value 0 will be output
4 The string "null" will be output
Which of the following statements are true?
1: Garbage collection is platform dependent
2: You can suggest when garbage collection will run but cannot be certain when it will take place
3: A reference to a primitive variable is eligable for garbage collection when it is set to null
4: The automatic garbage collection of the JVM prevents programs from ever running out of memory
2: You can suggest when garbage collection will run but cannot be certain when it will take place
3: A reference to a primitive variable is eligable for garbage collection when it is set to null
4: The automatic garbage collection of the JVM prevents programs from ever running out of memory
Subscribe to:
Posts (Atom)