java oDESK TEST ANSWER

61)What would happen on compiling and running the following code?

public class Test
{
    public static void main (String args[])
    {
    TestThread t = new TestThread ();
    t.setValue (5);
    t.start ();
    t.setValue (10);
    }
}
class TestThread extends Thread
    {
    private int value;
    synchronized public void setValue (int v)
    {
        value = v;
    }
    public void run ()
    {
    System.out.println ("before: " + value);
    setValue (50);
    System.out.println ("after: " + value);
    }
}

a. When run, this code will always print ''before: 10'' and ''after: 50''
b. When run, this code will always print ''before: 5'' and ''after: 50''
c. When run, this code will always print ''before: 5'' and ''after: 10''
d. It is not possible to predict what will be printed, it might print different things regarding the order in which the statements are executed

answer:A

62)What would be the result of compiling and running the following code class?

public class Test
{
public static void main (String args[])
{
Test t = new Test ();
t.start ();
}
public void start ()
{
int i = 2;
int j = 3;
int x = i & j;
System.out.println (x);
}
}

a. The code will not compile
b. The code will compile but will give runtime error
c. The code will compile and print 2
d. The code will compile and print 1

answer:C

63)Is the following statement true or false?

A .java file without any source code is a valid java file.

a. True
b. False

answer:A

64)Can Java be used to send ICMP packets?

a. Yes
b. No

answer:B

65)Which of the following is a benefit derived from using OOPS?

a. Elimination of redundant code
b. Reusing the code
c. Ability to enhance and extend previously written code for new modules
d. Co-existence of multiple instances of objects
e. All of the above

answer:C

66)Can ServerSocket be used with UDP?

a. Yes
b. No

answer:B

67)Inheritance is a process by which the objects of parent class acquire the properties of the child class.

a. True
b. False

answer:B

68)Are the following two statements equivalent?

A: Thread.yield ();
B: Thread.sleep (0);

a. Yes
b. No

answer:B

69)You have three classes named A, B, and C. The class B is derived from class A and class C is derived from B. Which of the following relations are correct for the given classes?

a. Any instance of A is an instance of B
b. Any instance of B is an instance of A
c. Any instance of C is an instance of B
d. Any instance of B is an instance of C

answer:A,D

70)Can InetAddress be used with inet6?

a. Yes
b. No
c. No, InetAddress is an abstract class

answer:A

71)Which of these interfaces are used by implementations of models for JTable?

a. TableModel
b. TableColumnModel
c. TableSelectionModel
d. ListModel

answer:A,B

72)What is the method by which two or more applets can communicate with each other within one HTML page?

a. Multiple applets cannot communicate with each other within one HTML page
b. getCodeBase()
c. getDefaultContext()
d. getAppletContext()

answer:D

73)What is the return type of the method ceil(double) from the Math class?

a. int
b. float
c. double
d. Integer
e. Double

answer:C

74)Which of the following are wrapper classes?

a. java.lang.Math
b. java.lang.Boolean
c. java.lang.Long
d. java.lang.Float

answer:B,C,D

75)What happens on attempting to compile and run the following code?

public class Graft
{
public static void main(String argv[])
{
Graft g = new Graft();
}
protected Graft()
{
for(int i =0; i <10; i ++)
{
System.out.println(i);
}
}
}

a. A Compilation error occurs because constructors cannot be declared protected
b. Successful compilation with output 0 to 9
c. A runtime error occurs because constructors cannot be declared protected
d. Successful compilation with output 0 to 10

answer:B

76)Choose all valid forms of the argument list for the FileOutputStream constructor shown below:

a. FileOutputStream( FileDescriptor fd )
b. FileOutputStream( String n, boolean a )
c. FileOutputStream( boolean a )
d. FileOutputStream()
e. FileOutputStream( File f )

answer:A,B,E

77)What will the length() method in the File class return?

a. The number of characters in the file
b. The number of bytes in the file
c. The number of lines in the file
d. None of the above

answer:B

78)You have a class called TwoTyre. Its main method is as follows:

public static void main(String bicycle[])
{
        System.out.println(bicycle[0]);
}
On the command line you typed:
java TwoTyre one two
what would be the result?

a. one
b. two
c. TwoTyre
d. None of the above

answer:A

79)What will be the output of the following program?

public class Test
{
    public static void main (String args[ ])
    {
        B o = new A ();
        System.out.println (o.content ());
    }
    public String content () throws Exception
    {
        throw new Exception (''This is an exception on this.content ()'');
    }
    private static class B
    {
        public String content ()
        {
        return ''B'';
        }
     }
     private static class A extends B
     {
        public String content ()
        {
           return ''A'';
        }
     }
}

a. The code will compile but will fail to run
b. The code will compile and on running, it will print ''A''
c. The code will fail to compile
d. The code will compile and on running, it will print ''B''

answer:B

80)What is the superclass of java.net.DatagramSocket?

a. java.net.Socket
b. java.net.UDPSocket
c. java.net.SocketInterface
d. java.lang.Object
e. None of the above

answer:A

81)Which of the following are the methods of the Thread class?

a. stay()
b. go()
c. yield()
d. sleep(long millis)

answer:C,D

82)What is true regarding the Datagram Protocol (UDP)?

a. A message is never partial
b. Messages order is guaranteed
c. Messages are not guaranteed to arrive at destination
d. UDP is MTU independant
e. None is true

answer:B

83)What should be the replacement of "//ABC" in the following code?

class Krit
{
    String str= new String("OOPS !!! JAVA");
    public void KritMethod(final int iArgs)
    {
      int iOne;
      class Bicycle
      {
        public void sayHello()
        {
          //ABC
        }
      }
    }
    public void Method2()
    {
      int iTwo;
    }
}

a. System.out.print(str);
b. System.out.print(iOne);
c. System.out.print(iTwo);
d. System.out.print(iArgs);

answer:A,D

84)Which of the following statements is true of the HashMap class?

a. It stores information as key/value pairs
b. Elements are returned in the order they were added
c. It does not permit null keys
d. It does not permit null values

answer:A

85)Which of the following is a short circuit operator?

a. &&
b. ||
c. |
d. &

answer:A,B

86)What will be the output when this code is compiled and run?

public class Test
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}
private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}
public static void main (String args[])
{
new Test ();
}
private class Bar
{
public int x = 10;
}
}

a. The code will fail to compile
b. 11 12
c. 11 11
d. 12 12

answer:B

87)Which of the following require explicit try/catch exception handling by the programmer?

a. Accessing a method in another class
b. Attempting to open a network socket
c. Attempting to open a file
d. Traversing each member of an array

answer:B,C

88)Assuming that val has been defined as an int for the code below, which values of val will result in "Test C" being printed?

if( val > 4 ) {
   System.out.println("Test A");
}else if( val > 9 ) {
   System.out.println("Test B");
}else
   System.out.println("Test C");

a. val < 0
b. val between 0 and 4
c. val between 4 and 9
d. val > 9
e. val = 0
f. No values for val will result in "Test C" being printed

answer:A,B,E

89)What would happen on compiling and running the following code?

public class Anchor
{
public static void main(String[] argv)
{
new Anchor();
}
public Anchor()
{
String s[][] = new String[2][2];
System.out.println(s[1][1]);
System.out.println(s[1][2]);
}
}

a. Compilation error
b. Compiles and prints two blank lines at runtime
c. Compiles and prints null followed by ArrayIndexOutOfBoundsException
d. Compiles and prints a blank line followed by ArrayIndexOutOfBoundsException

answer:C

90)Which of the following is a short circuit operator?

a. &&
b. ||
c. |
d. &

answer:A,B

91)Which of the following methods will cause a thread to stop?
a. Invoking the interrupt() of the thread
b. Invoking the sleep() method on thread
c. When execution of the run() method ends
d. None of the above

answer:B

92)Which of the following will ensure that garbage collection runs?
a. System.free()
b. Runtime.gc()
c. Object.gc()
d. System.gc()
e. None of the above

answer:D

93)Which of the following statement will not compile?
a. File f = new File("/","autoexec.bat");
b. DataInputStream d = new DataInputStream(System.in);
c. RandomAccessFile r = new RandomAccessFile("OutFile");
d. OutputStreamWriter o = new OutputStreamWriter(System.out);

answer:C

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...