Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Monday, April 14, 2008

Core Java Test Paper1 116

Which of the following will output -4.0
1) System.out.println(Math.floor(-4.7));
2) System.out.println(Math.round(-4.7));
3) System.out.println(Math.ceil(-4.7));
4) System.out.println(Math.min(-4.7));
Question 25)
What will happen if you attempt to compile and run the
following code?
Integer ten=new Integer(10);
Long nine=new Long (9);
System.out.println(ten + nine);
int i=1;
System.out.println(i + ten);
1) 19 followed by 20
2) 19 followed by 11
3) Error: Can't convert java lang Integer
4) 10 followed by 1
Question 33)
What will happen when you attempt to compile and run the
following code?.
1) It will compile and the run method will print out the
increasing value of i.
2) It will compile and calling start will print out the
increasing value of i.
3) The code will cause an error at compile time.
4) Compilation will cause an error because while cannot take a
parameter of true.
class Background implements Runnable{
int i=0;
public int run(){
while(true){
i++;
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
System.out.println("i="+i);
} //End while
return 1;
}//End run
}//End class
Question 38)
How can you change the current working directory using an
instance of the File class called FileName?
1) FileName.chdir("DirName")
2) FileName.cd("DirName")
3) FileName.cwd("DirName")
4) The File class does not support directly changing the
current directory.
Question 46)
You need to create a class that will store a unique object
elements. You do not need to sort these elements but they must
be unique.
What interface might be most suitable to meet this need?
1)Set
2)List
3)Map
4)Vector
Question 47)
Which of the following will successfully create an instance of
the Vector class and add an element?
1) Vector v=new Vector(99);
v[1]=99;
2) Vector v=new Vector();
v.addElement(99);
3) Vector v=new Vector();
v.add(99);
4 Vector v=new Vector(100);
v.addElement("99");
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
Question 49)
What will be the result when you attempt to compile this
program?
public class Rand{
public static void main(String argv[]){
int iRand;
iRand = Math.random();
System.out.println(iRand);
}
}
1) Compile time error referring to a cast problem
2) A random number between 1 and 10
3) A random number between 0 and 1
4) A compile time error about random being an unrecognised
method
Question 50)
Given the following code
import java.io.*;
public class Th{
public static void main(String argv[]){
Th t = new Th();
t.amethod();
}
public void amethod(){
try{
ioCall();
}catch(IOException ioe){}
}
}
What code would be most likely for the body of the ioCall
method
1) public void ioCall ()throws IOException{
DataInputStream din = new DataInputStream(System.in);
din.readChar();
}
2) public void ioCall ()throw IOException{
DataInputStream din = new DataInputStream(System.in);
din.readChar();
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
}
3) public void ioCall (){
DataInputStream din = new DataInputStream(System.in);
din.readChar();
}
4) public void ioCall throws IOException(){
DataInputStream din = new DataInputStream(System.in);
din.readChar();
}
Question 53)
Which of the following can you perform using the File class?
1) Change the current directory
2) Return the name of the parent directory
3) Delete a file
4) Find if a file contains text or binary information
Question 55)
You are concerned that your program may attempt to use more
memory than is available. To avoid this situation you want to
ensure that the Java Virtual Machine will run its garbage
collection just before you start a complex routine. What can
you do to be certain that garbage collection will run when you
want .
1) You cannot be certain when garbage collection will run
2) Use the Runtime.gc() method to force garbage collection
3) Ensure that all the variables you require to be garbage
collected are set to null
4) Use the System.gc() method to force garbage collection
jd2
8) What will happen when you attempt to compile and run this
code?
private class Base{}
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
public class Vis{
transient int iVal;
public static void main(String elephant[]){
}
}
1)Compile time error: Base cannot be private
2)Compile time error indicating that an integer cannot be
transient
3)Compile time error transient not a data type
4)Compile time error malformed main method
9) What happens when you attempt to compile and run these two
files in the same directory?
//File P1.java
package MyPackage;
class P1{
void afancymethod(){
System.out.println("What a fancy method");
}
}
//File P2.java
public class P2 extends P1{
afancymethod();
}
1) Both compile and P2 outputs "What a fancy method" when run
2) Neither will compile
3) Both compile but P2 has an error at run time
4) P1 compiles cleanly but P2 has an error at compile time
Question 18)
What will happen when you attempt to compile and run the
following code?
public class Bground extends Thread{
public static void main(String argv[]){
Bground b = new Bground();
b.run();
}
public void start(){
for (int i = 0; i <10; i++){
System.out.println("Value of i = " +
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
i);
}
}
}
Question 20)
Which most closely matches a description of a Java Map?
1) A vector of arrays for a 2D geographic representation
2) A class for containing unique array elements
3) A class for containing unique vector elements
4) An interface that ensures that implementing classes cannot
contain duplicate keys
Question 21)
How does the set collection deal with duplicate elements?
1) An exception is thrown if you attempt to add an element
with a duplicate value
2) The add method returns false if you attempt to add an
element with a duplicate value
3) A set may contain elements that return duplicate values
from a call to the equals method
4) Duplicate values will cause an error at compile time
Question 22)
What can cause a thread to stop executing?
1) The program exits via a call to System.exit(0);
2) Another thread is given a higher priority
3) A call to the thread's stop method.
4) A call to the halt method of the Thread class
Question 23)
For a class defined inside a method, what rule governs access
to the variables of the enclosing method?
1) The class can access any variable
2) The class can only access static variables
3) The class can only access transient variables
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
4) The class can only access final variables
Question 24)
Under what circumstances might you use the yield method of the
Thread class
1) To call from the currently running thread to allow another
thread of the same priority to run
2) To call on a waiting thread to allow it to run
3) To allow a thread of higher priority to run
4) To call from the currently running thread with a parameter
designating which thread should be allowed to run
Question 25)
What will happen when you attempt to compile and run the
following code
public class Hope{
public static void main(String argv[]){
Hope h = new Hope();
}
protected Hope(){
for(int i =0; i <10; i ++){
System.out.println(i);
}
}
}
1) Compilation error: Constructors cannot be declared
protected
2) Run time error: Constructors cannot be declared protected
3) Compilation and running with output 0 to 10
4) Compilation and running with output 0 to 9
Question 26)
What will happen when you attempt to compile and run the
following code
public class MySwitch{
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
public static void main(String argv[]){
MySwitch ms= new MySwitch();
ms.amethod();
}
public void amethod(){
int k=10;
switch(k){
default: //Put the default at the bottom, not here
System.out.println("This is the default output");
break;
case 10:
System.out.println("ten");
case 20:
System.out.println("twenty");
break;
}
}
}
1) None of these options
2) Compile time errror target of switch must be an integral
type
3) Compile and run with output "This is the default output"
4) Compile and run with output "ten"
Question 27)
Which of the following is the correct syntax for suggesting
that the JVM performs garbage collection
1) System.free();
2) System.setGarbageCollection();
3) System.out.gc();
4) System.gc();
Question 28)
What will happen when you attempt to compile and run the
following code
public class As{
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
int i = 10;
int j;
char z= 1;
boolean b;
public static void main(String argv[]){
As a = new As();
a.amethod();
}
public void amethod(){
System.out.println(j);
System.out.println(b);
}
}
1) Compilation succeeds and at run time an output of 0 and
false
2) Compilation succeeds and at run time an output of 0 and
true
3) Compile time error b is not initialised
4) Compile time error z must be assigned a char value
Question 29)
What will happen when you attempt to compile and run the
following code with the command line "hello there"
public class Arg{
String[] MyArg;
public static void main(String argv[]){
MyArg=argv;
}
public void amethod(){
System.out.println(argv[1]);
}
}
1) Compile time error
2) Compilation and output of "hello"
3) Compilation and output of "there"
4) None of the above
Question 30)
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
What will happen when you attempt to compile and run the
following code
public class StrEq{
public static void main(String argv[]){
StrEq s = new StrEq();
}
private StrEq(){
String s = "Marcus";
String s2 = new String("Marcus");
if(s == s2){
System.out.println("we have a match");
}else{
System.out.println("Not equal");
}
}
}
1) Compile time error caused by private constructor
2) Output of "we have a match"
3) Output of "Not equal"
4) Compile time error by attempting to compare strings using
==
Question 31)
1) What will happen when you attempt to compile and run the
following code
import java.io.*;
class Base{
public static void amethod()throws FileNotFoundException{}
}
public class ExcepDemo extends Base{
public static void main(String argv[]){
ExcepDemo e = new ExcepDemo();
}
public static void amethod(){}
protected ExcepDemo(){
try{
DataInputStream din = new DataInputStream(System.in);
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
System.out.println("Pausing");
din.readChar();
System.out.println("Continuing");
this.amethod();
}catch(IOException ioe) {}
}
}
1)Compile time error caused by protected constructor
2) Compile time error caused by amethod not declaring
Exception
3) Runtime error caused by amethod not declaring Exception
4) Compile and run with output of "Pausing" and "Continuing"
after a key is hit
Question 32)
What will happen when you attempt to compile and run this
program
public class Outer{
public String name = "Outer";
public static void main(String argv[]){
Inner i = new Inner();
i.showName();
}//End of main
private class Inner{
String name =new String("Inner");
void showName(){
System.out.println(name);
}
}//End of Inner class
}
1) Compile and run with output of "Outer"
2) Compile and run with output of "Inner"
3) Compile time error because Inner is declared as private
4) Compile time error because of the line creating the
instance of Inner
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
Question 34)
Which option most fully describes will happen when you attempt
to compile and run the following code
public class MyAr{
public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
}
public void amethod(){
static int i;
System.out.println(i);
}
}
1) Compilation and output of the value 0
2) Compile time error because i has not been initialized
3) Compilation and output of null
4) Compile time error
Question 35)
Which of the following will compile correctly
1) short myshort = 99S;
2) String name = 'Excellent tutorial Mr Green';
3) char c = 17c;
4)int z = 015;
Question 36)
Which of the following are Java key words
1)double
2)Switch
3)then
4)instanceof
Question 37
What will be output by the following line?
System.out.println(Math.floor(-2.1));
1) -2
2) 2.0
3) -3
4) -3.0
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
Question 38)
Given the following main method in a class called Cycle and a
command line of
java Cycle one two
what will be output?
public static void main(String bicycle[]){
System.out.println(bicycle[0]);
}
1) None of these options
2) cycle
3) one
4) two
Question 39)
Which of the following statements are true?
1) At the root of the collection hierarchy is a class called
Collection
2) The collection interface contains a method called
enumerator
3) The interator method returns an instance of the Vector
class
4) The set interface is designed for unique elements
Question 41)
Given the following code
class Base{}
public class MyCast extends Base{
static boolean b1=false;
static int i = -1;
static double d = 10.1;
public static void main(String argv[]){
MyCast m = new MyCast();
Base b = new Base();
//Here
}
}
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
Which of the following, if inserted at the comment //Here will
allow the code to compile and run without error
1) b=m;
2) m=b;
3) d =i;
4) b1 =i;
Question 42)
Which of the following statements about threading are true
1) You can only obtain a mutually exclusive lock on methods in
a class that extends Thread or implements runnable
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a method
declared with the keyword synchronized
4) Thread scheduling algorithms are platform dependent
Question 43)
Your chief Software designer has shown you a sketch of the new
Computer parts system she is about to create. At the top of
the hierarchy is a Class called Computer and under this are
two child classes. One is called LinuxPC and one is called
WindowsPC. The main difference between the two is that one
runs the Linux operating System and the other runs the Windows
System (of course another difference is that one needs
constant re-booting and the other runs reliably). Under the
WindowsPC are two Sub classes one called Server and one Called
Workstation. How might you appraise your designers work?
1) Give the goahead for further design using the current
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
scheme
2) Ask for a re-design of the hierarchy with changing the
Operating System to a field rather than Class type
3) Ask for the option of WindowsPC to be removed as it will
soon be obsolete
4) Change the hierarchy to remove the need for the superfluous
Computer Class.
Question 44)
Objective 4.1)
Which of the following statements are true
1) An inner class may be defined as static
2) There are NO circumstances where an inner class may be
defined as private
3) An anonymous class may have only one constructor
4) An inner class may extend another class
Question 45)
What will happen when you attempt to compile and run the
following code
int Output=10;
boolean b1 = false;
if((b1==true) && ((Output+=10)==20)){
System.out.println("We are equal "+Output);
}else
{
System.out.println("Not equal! "+Output);
}
1) Compile error, attempting to peform binary comparison on
logical data type
2) Compilation and output of "We are equal 10"
3) Compilation and output of "Not equal! 20"
4) Compilation and output of "Not equal! 10"
Question 49)
Which of the following will compile without error?
1) File f = new File("/","autoexec.bat");
2) DataInputStream d = new DataInputStream(System.in);
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
3) OutputStreamWriter o = new OutputStreamWriter(System.out);
4) RandomAccessFile r = new RandomAccessFile("OutFile");
Question 50)
Given the folowing classes which of the following will compile
without error?
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace();
}
}
1)o1=o2;
2)b=ob;
3)ob=b;
4)o1=b;
Question 51)
Given the following code what will be the output?
class ValHold{
public int i = 10;
}
public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);
}//End of amethod
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
public void another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.println(v.i+ " "+i);
}//End of another
}
1) 10,0, 30
2) 20,0,30
3) 20,99,30
4) 10,0,20
Question 52)
Given the following class definition, which of the following
methods could be legally placed after the comment
//Here
public class Rid{
public void amethod(int i, String s){}
//Here
}
1)public void amethod(String s, int i){}
2)public int amethod(int i, String s){}
3)public void amethod(int i, String mystring){}
4) public void Amethod(int i, String s) {}
Question 53)
Given the following class definition which of the following
can be legally placed after the comment line
//Here ?
class Base{
public Base(int i){}
}
public class MyOver extends Base{
public static void main(String arg[]){
MyOver m = new MyOver(10);
}
MyOver(int i){
super(i);
}
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
MyOver(String s, int i){
this(i);
//Here
}
}
1)MyOver m = new MyOver();
2)super();
3)this("Hello",10);
4)Base b = new Base(10);
Question 54)
Given the following class definition, which of the following
statements would be legal after the comment //Here
class InOut{
String s= new String("Between");
public void amethod(final int iArgs){
int iam;
class Bicycle{
public void sayHello(){
//Here
}//End of bicycle class
}
}//End of amethod
public void another(){
int iOther;
}
}
1)System.out.println(s);
2) System.out.println(iOther);
3) System.out.println(iam);
4) System.out.println(iArgs);
Question 55)
Which of the following are methods of the Thread class?
1) yield()
2) sleep(long msec)
3) go()
4) stop()
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
Question 56)
Which of the following methods are members of the Vector class
and allow you to input a new element
1) addElement
2) insert
3) append
4) addItem
Question 57)
Which of the following statements are true?
1) Adding more classes via import statements will cause a
performance overhead, only import classes you actually use.
2) Under no circumstances can a class be defined with the
private modifier
3) A inner class may under some circumstances be defined with
the protected modifier
4) An interface cannot be instantiated
Question 59)
Which of the following are methods of the Collection
interface?
1) iterator
2) isEmpty
3) toArray
4) setText
Question 60)
Which of the following best describes the use of the
synhronized keyword?
1) Allows two process to run in paralell but to communicate
with each other
2) Ensures only one thread at a time may access a class or
object
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
3) Ensures that two or more processes will start and end at
the same time
4) Ensures that two or more Threads will start and end at the
same time
JD4
Q 1. What is the output of the following
StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2= new StringBuffer("Amit");
String ss1 = "Amit";
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2));
System.out.println(sb1.equals(ss1));
System.out.println("Poddar".substring(3));
Ans:
a) false
false
false
dar
b) false
true
false
Poddar
c) Compiler Error
d) true
true
false
dar
Q9. What is the output of following if the return value is "the value 0 if the argument
string is equal to this string; a value less than 0 if this string is lexicographically less than
the string argument; and a value greater than 0 if this string is lexicographically greater
than the string argument" (Assuming written inside main)
String s5 = "AMIT";
String s6 = "amit";
System.out.println(s5.compareTo(s6));
System.out.println(s6.compareTo(s5));
System.out.println(s6.compareTo(s6));
Ans
a> -32
32
0
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
b> 32
32
0
c> 32
-32
0
d> 0
0
0
Q 10) What is the output (Assuming written inside main)
String s1 = new String("amit");
String s2 = s1.replace('m','i');
s1.concat("Poddar");
System.out.println(s1);
System.out.println((s1+s2).charAt(5));
a) Compile error
b) amitPoddar
o
c) amitPoddar
i
d) amit
i
Q 11) What is the output (Assuming written inside main)
String s1 = new String("amit");
System.out.println(s1.replace('m','r'));
System.out.println(s1);
String s3="arit";
String s4="arit";
String s2 = s1.replace('m','r');
System.out.println(s2==s3);
System.out.println(s3==s4);
a) arit
amit
false
true
b) arit
arit
false
true
c) amit
amit
false
true
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
d) arit
amit
true
true
Q12) Which one does not extend java.lang.Number
1)Integer
2)Boolean
3)Character
4)Long
5)Short
Q13) Which one does not have a valueOf(String) method
1)Integer
2)Boolean
3)Character
4)Long
5)Short
Q.14) What is the output of following (Assuming written inside main)
String s1 = "Amit";
String s2 = "Amit";
String s3 = new String("abcd");
String s4 = new String("abcd");
System.out.println(s1.equals(s2));
System.out.println((s1==s2));
System.out.println(s3.equals(s4));
System.out.println((s3==s4));
a) true
true
true
false
b) true
true
true
true
c) true
false
true
false
Q17) What will be the output of line 5
1 Choice c1 = new Choice();
2 c1.add("First");
3 c1.addItem("Second");
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
4 c1.add("Third");
5 System.out.println(c1.getItemCount());
a) 1
b) 2
c) 3
d) None of the above
Q18) What will be the order of four items added
Choice c1 = new Choice();
c1.add("First");
c1.addItem("Second");
c1.add("Third");
c1.insert("Lastadded",2);
System.out.println(c1.getItemCount());
a) First,Second,Third,Fourth
b) First,Second,Lastadded,Third
c) Lastadded,First,Second,Third
Q19) Answer based on following code
1 Choice c1 = new Choice();
2 c1.add("First");
3 c1.addItem("Second");
4 c1.add("Third");
5 c1.insert("Lastadded",1000);
6 System.out.println(c1.getItemCount());
a) Compile time error
b) Run time error at line 5
c) No error and line 6 will print 1000
d) No error and line 6 will print 4
Q24. Q. What will be the output of follwing
{
double d1 = -0.5d;
System.out.println("Ceil for d1 " + Math.ceil(d1));
System.out.println("Floor for d1 " +Math.floor(d1));
}
Answers:
a) Ceil for d1 0
Floor for d1 -1;
b) Ceil for d1 0
Floor for d1 -1.0;
c) Ceil for d1 0.0
Floor for d1 -1.0;
d) Ceil for d1 -0.0
Floor for d1 -1.0;
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
Q25. What is the output of following
{
float f4 = -5.5f;
float f5 = 5.5f;
float f6 = -5.49f;
float f7 = 5.49f;
System.out.println("Round f4 is " + Math.round(f4));
System.out.println("Round f5 is " + Math.round(f5));
System.out.println("Round f6 is " + Math.round(f6));
System.out.println("Round f7 is " + Math.round(f7));
}
a)Round f4 is -6
Round f5 is 6
Round f6 is -5
Round f7 is 5
b)Round f4 is -5
Round f5 is 6
Round f6 is -5
Round f7 is 5
Q26. Given Integer.MIN_VALUE = -2147483648
Integer.MAX_VALUE = 2147483647
What is the output of following
{
float f4 = Integer.MIN_VALUE;
float f5 = Integer.MAX_VALUE;
float f7 = -2147483655f;
System.out.println("Round f4 is " + Math.round(f4));
System.out.println("Round f5 is " + Math.round(f5));
System.out.println("Round f7 is " + Math.round(f7));
}
a)Round f4 is -2147483648
Round f5 is 2147483647
Round f7 is -2147483648
b)Round f4 is -2147483648
Round f5 is 2147483647
Round f7 is -2147483655
Q27)
1 Boolean b1 = new Boolean("TRUE");
2 Boolean b2 = new Boolean("true");
3 Boolean b3 = new Boolean("JUNK");
4 System.out.println("" + b1 + b2 + b3);
a) Comiler error
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
b) RunTime error
c)truetruefalse
d)truetruetrue
Q 28) In the above Question if line 4 is changed to
System.out.println(b1+b2+b3); The output is
a) Compile time error
b) Run time error
c) truetruefalse
d) truetruetrue
Q 29. What is the output
{
Float f1 = new Float("4.4e99f");
Float f2 = new Float("-4.4e99f");
Double d1 = new Double("4.4e99");
System.out.println(f1);
System.out.println(f2);
System.out.println(d1);
}
a) Runtime error
b) Infinity
-Infinity
4.4E99
c) Infinity
-Infinity
Infinity
d) 4.4E99
-4.4E99
4.4E99
Q30 Q. Which of the following wrapper classes can not
take a "String" in constructor
1) Boolean
2) Integer
3) Long
4) Character
5) Byte
6) Short
Q31. What is the output of following
Double d2 = new Double("-5.5");
Double d3 = new Double("-5.5");
System.out.println(d2==d3);
System.out.println(d2.equals(d3));
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
a) true
true
b) false
false
c) true
false
d) false
true
Q37) Consider a directory structure like this (NT or 95)
C:\JAVA\12345.msg --FILE
\dir1\IO.class -- IO.class is under dir1
Consider the following code
import java.io.*;
public class IO {
public static void main(String args[]) {
File f = new File("..\\12345.msg");
try{
System.out.println(f.getCanonicalPath());
System.out.println(f.getAbsolutePath());
}catch(IOException e){
System.out.println(e);
}
}
}
What will be the output of running "java IO" from C:\java\dir1
a) C:\java\12345.msg
C:\java\dir1\..\12345.msg
b) C:\java\dir1\12345.msg
C:\java\dir1\..\12345.msg
c) C:\java\dir1\..\12345.msg
C:\java\dir1\..\12345.msg
Q 38) Suppose we copy IO.class from C:\java\dir1 to c:\java
What will be the output of running "java IO" from C:\java.
a) C:\java\12345.msg
C:\java\..\12345.msg
b) C:\12345.msg
C:\java\..\12345.msg
c) C:\java\..\12345.msg
C:\java\\..\12345.msg
Q39) Which one of the following methods of java.io.File throws IOException and why
a) getCanonicalPath and getAbsolutePath both require filesystem queries.
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
b) Only getCannonicalPath as it require filesystem queries.
c) Only getAbsolutePath as it require filesystem queries.
Q40) What will be the output if
Consider a directory structure like this (NT or 95)
C:\JAVA\12345.msg --FILE
\dir1\IO.class -- IO.class is under dir1
import java.io.*;
public class IO {
public static void main(String args[]) {
File f = new File("12345.msg");
String arr[] = f.list();
System.out.println(arr.length);
}
}
a) Compiler error as 12345.msg is a file not a directory
b) java.lang.NullPointerException at run time
c) No error , but nothing will be printed on screen
Q41) What will be the output
Consider a directory structure like this (NT or 95)
C:\JAVA\12345.msg --FILE
import java.io.*;
public class IO {
public static void main(String args[]) {
File f1 = new File("\\12345.msg");
System.out.println(f1.getPath());
System.out.println(f1.getParent());
System.out.println(f1.isAbsolute());
System.out.println(f1.getName());
System.out.println(f1.exists());
System.out.println(f1.isFile());
}
}
a) \12345.msg
\
true
12345.msg
true
true
b) \12345.msg
\
true
\12345.msg
false
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
false
c) 12345.msg
\
true
12345.msg
false
false
d) \12345.msg
\
true
12345.msg
false
false
Q42) If in Question no 41 the line
File f1 = new File("\\12345.msg"); is replaced with File f1 = new File("12345.msg");
What will be the output
a) 12345.msg
\
true
12345.msg
true
true
b) 12345.msg
null
true
12345.msg
true
true
c) 12345.msg
null
false
12345.msg
true
true
d) \12345.msg
\
true
12345.msg
false
false
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
Question 1
What will happen if you compile/run this code?
1: public class Q1 extends Thread
2: {
3: public void run()
4: {
5: System.out.println("Before start method");
6: this.stop();
7: System.out.println("After stop method");
8: }
9:
10: public static void main(String[] args)
11: {
12: Q1 a = new Q1();
13: a.start();
14: }
15: }
A) Compilation error at line 7.
B) Runtime exception at line 7.
C) Prints "Before start method" and "After stop method".
D) Prints "Before start method" only.
Question 2
What will happen if you compile/run the following code?
1: class Test
2: {
3: static void show()
4: {
5: System.out.println("Show method in Test class");
6: }
7:}
8:
9: public class Q2 extends Test
10: {
11: static void show()
12: {
13: System.out.println("Show method in Q2 class");
14: }
15: public static void main(String[] args)
16: {
17: Test t = new Test();
Haaris Infotech - Shoiab - 9840135749
Core Java - Test - 50 Marks
18: t.show();
19: Q2 q = new Q2();
20: q.show();
21:
22: t = q;
23: t.show();
24:
25: q = t;
26: q.show();
27: }
28: }
A) prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Q2 class"
"Show method in Q2 class"
B) prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Test class"
"Show method in Test class"
C) prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Test class"
"Show method in Q2 class"
D) Compilation error.

No comments:

Archives