wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Week 2 Quiz

Total questions: 20

Worksheet time: 40mins

Name
Class
Date
1.

Which method when implemented must return true while there are still more elements to extract, and false when all the elements have been enumerated?

a)

Object nextElement( )

b)

 boolean hasMoreElements( )

c)

Both A & B

d)

None of the above

2.

Consider the following two statements

int x = 25;

Integer y = new Integer(33);

What is the difference between these two statements?

a)

Primitive data types

b)

 primitive data type and an object of a wrapper class

c)

Wrapper class

d)

None of the above

3.

Which allows the caller to remove elements from the underlying collection during the iteration with well-defined semantics?

a)

 Enumeration

b)

Iterator

c)

None of the above

4.

Filtered streams are simply wrappers around underlying input or output streams that transparently provide some extended level of functionality.

a)

True

b)

False

5.

Where are the primitive data type values stored?

a)

Heap Memory

b)

Stack Memory

c)

Both A & B

d)

None of the above

6.

 What will be the output of the following Java code?

import java.util.*;

   public class genericstack <E>

   {

       Stack <E> stk = new Stack <E>();

public void push(E obj)

       {

           stk.push(obj);

}

public E pop()

       {

           E obj = stk.pop();

    return obj;

}

   }

   class Output

   {

       public static void main(String args[])

       {

           genericstack <String> gs = new genericstack<String>();

           gs.push("Hello");

           System.out.println(gs.pop());

       }

   }

a)

H

b)

Hello

c)

Runtime Error

d)

Compilation Error

7.

Which of these Exception handlers cannot be parameterized?

a)

catch

b)

throw

c)

throws

d)

 all of the mentioned

8.

What will be the output of the following Java program?

   import java.util.*;

   public class genericstack <E>

   {

       Stack <E> stk = new Stack <E>();

public void push(E obj)

       {

           stk.push(obj);

}

public E pop()

       {

           E obj = stk.pop();

    return obj;

}

   }

   class Output

   {

       public static void main(String args[])

       {

           genericstack <Integer> gs = new genericstack<Integer>();

           gs.push(36);

           System.out.println(gs.pop());

       }

   }

a)

H

b)

Hello

c)

 Runtime Error

d)

Compilation Error

9.

Which of these packages contain all the collection classes?

a)

java.lang

b)

java.util

c)

java.net

d)

 java.awt

10.

What will be the output of the following Java program?

   import java.util.*;

   class Bitset

   {

       public static void main(String args[])

       {

           BitSet obj = new BitSet(5);

           for (int i = 0; i < 5; ++i)

               obj.set(i);

           obj.clear(2);

           System.out.print(obj);

       }

   }

a)

 {0, 1, 3, 4}

b)

{0, 1, 2, 4}

c)

 {0, 1, 2, 3, 4}

d)

 {0, 0, 0, 3, 4}

11.

Which of the these exceptions is thrown in the case when file in which you want to write is not found:-

a)

IOException

b)

FileNotFoundException

c)

FileException

d)

None of the above

12.

What value is returned by the read() method when it encounters EOF:-

a)

Null

b)

-1

c)

0

d)

1

13.

 Which of the following classes allow us to write the file:-

a)

FileStream

b)

ByteStream

c)

FileInputStream

d)

FileBufferStream

14.

What will be the output of the following code:-

import java.io.*;

    class files 

    {

        public static void main(String args[]) 

        {

            File obj = new File(""/java/spring"");

            System.out.print(obj.getName());

        }

    }

a)

spring

b)

/java/spring

c)

java

d)

None of the above

15.

In java how many streams are there by default?

a)

1

b)

2

c)

3

d)

4

16.

Which of the following is a type of stream available in Java:-

a)

Integer Stream

b)

Float Stream

c)

Double Stream

d)

Byte Stream

17.

 Which of the following classes contains print and println method:-

a)

PrintStream

b)

System.out

c)

BufferedOutputStream

d)

System

18.

Which of the following can be used to write in console:-

a)

println()

b)

write()

c)

print()

d)

All of the following

19.

Which of the following is not a member of java.io:

a)

StringReader

b)

String

c)

File

d)

Writer

20.

Which method returns true when called on a file and false when called on a directory?

a)

IsFile()

b)

isFile()

c)

isfile()

d)

Isfile()