sdp200

Description

Quiz on sdp200, created by Hello World on 18/01/2017.
Hello World
Quiz by Hello World, updated more than 1 year ago
Hello World
Created by Hello World over 7 years ago
733
1

Resource summary

Question 1

Question
1. What will be the output of the program?<br>
Answer
  • o Pine
  • o Oak
  • o Tree
  • o Forest
  • o Oops

Question 2

Question
2. Select how you would run your program to cause it to print: Arg is 2 <br>
Answer
  • o java Myfile 2 2 2
  • o java Myfile 1 2 2 3 4
  • o java Myfile 1 3 2 2
  • o java MyFile 1 2 2 2
  • o java Myfile 0 1 2 3

Question 3

Question
3. [html]What does the following code do? <br>void blur(char[] z, String st) {<br> if(z.length < st.length()) retrun; <br> for(int i = 0; i < st.length(); i++) <br> z[i] = st.charAt(i); <br>}
Answer
  • o It determines if the array contains the same characters as the String
  • o It copies characters from the array to the String
  • o It copies characters from the String to the array;
  • o It creates a new array that contains the same characters as the String

Question 4

Question
4. Given the declaration of an array : int[] a = {1,2,3,4,5}; What is the value of a[4]?
Answer
  • o 2
  • o 3
  • o 4
  • o 5
  • o 1

Question 5

Question
5. An array holds:
Answer
  • o Similar values of same data type
  • o Different values of same data type
  • o Same values of different data types
  • o Different values of different data types

Question 6

Question
6. [html]Java uses call by value. What is the value that is being passed into the routine by the method call in the following? <br> double rats[] = {1.2 , 2.3, 3.4}; <br> routine(rats);
Answer
  • o A copy of the array rats
  • o The value of the elements of rats
  • o A reference of the array
  • o 1.2
  • o 2.3

Question 7

Question
7. What is the prototype of the default constructor?<br>
Answer
  • o Test()
  • o Test
  • o public Test()
  • o public Test(void)
  • o Test(void)

Question 8

Question
8. What is the widest valid returnType for methodA in line 3?<br>
Answer
  • o int
  • o long
  • o byte
  • o double
  • o void

Question 9

Question
9. You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?
Answer
  • o java.util.Map
  • o java.util.Set
  • o java.util.Tree
  • o java.util.List
  • o java.util.Collection

Question 10

Question
10. You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
Answer
  • o public
  • o private
  • o protected
  • o transient
  • o volatile

Question 11

Question
11. Let’s assume that you have class C and interface I ? Which of the following is correct statement?
Answer
  • o class C implements I
  • o class C extends I
  • o interface I extends C
  • o interface I implements C
  • o class I implements C

Question 12

Question
12. Which is valid in a class that extends class A?<br>
Answer
  • o public int method1(int a, int b) {return 0; }
  • o private int method1(int a, int b) {return 0; }
  • o protected static int method1(int a, int b) {return 0; }
  • o public long method1(int a, int b) {return 0; }
  • o public static int method1(int a, int b) {return 0; }

Question 13

Question
13. Which statement is true?
Answer
  • o catch(X x) can catch subclasses of X where X is a subclass of Exception.
  • o The Error class is a RuntimeException.
  • o Any statement that can throw an Error must be enclosed in a try block
  • o Any statement that can throw an Exception must be enclosed in a try block

Question 14

Question
14. What will be the output of the program?<br>
Answer
  • o one two three four
  • o one two three four one
  • o four three two one
  • o four one three two

Question 15

Question
15. Given a method in a class, what access modifier do you use to restrict access to that method to only the other members of the same class?
Answer
  • o final
  • o public
  • o private
  • o protected
  • o static
  • o volatile

Question 16

Question
16. [html] Which three statements are true? <br> 1. The default constructor initialises method variables.<br> 2. The default constructor has the same access as its class.<br> 3. The default constructor invokes the no-arg constructor of the superclass.<br> 4. If a class lacks a no-arg constructor, the compiler always creates a default constructor. <br> 5. The compiler creates a default constructor only when there are no other constructors for the class.
Answer
  • o 1,2,4
  • o 2,3,5
  • o 3,4,5
  • o 1,2,3
  • o 1,3,5

Question 17

Question
17. What will be the output of the program?<br>
Answer
  • o AC
  • o ACD
  • o BD
  • o ABCD
  • o ABD

Question 18

Question
18. What will be the output of the program after the running program in such way :/> java Test red green blue?<br>
Answer
  • o baz =
  • o baz = blue
  • o baz = null
  • o Runtime Exception
  • o Compilation Error

Question 19

Question
19. Which is a valid declaration within an interface?
Answer
  • o public static final short stop = 23;
  • o protected short stop = 23;
  • o transient short stop = 23;
  • o final void madness(short stop);
  • o void madness(short stop) = 0;

Question 20

Question
20. Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
Answer
  • o java.util.HashSet
  • o java.util.LinkedList
  • o java.util.ArrayList
  • o java.util.List
  • o java.util.TreeSet

Question 21

Question
21. Which interface provides the capability to store objects using a key-value pair?
Answer
  • o java.util.Map
  • o java.util.Set
  • o java.util.List
  • o java.util.Collection
  • o java.util.ArrayList

Question 22

Question
22. [html]Which of the following statements about the hashcode() method are incorrect? <br> 1.The value returned by hashcode() is used in some collection classes to help locate objects <br> 2. The hashcode() method is required to return a positive int value <br> 3. The hashcode() method in the String class is the one inherited from Object <br> 4. Two new empty String objects will produce identical hashcodes
Answer
  • o 1 and 2
  • o 2 and 3
  • o 3 and 4
  • o 1 and 4
  • o 2 and 4

Question 23

Question
23. Which class or interface defines the wait(), notify(),and notifyAll() methods?
Answer
  • o Object
  • o Thread
  • o Runnable
  • o Class

Question 24

Question
24. What will be the output of the program? <br>
Answer
  • o It will print the numbers from 0 to 19 sequentially
  • o It will print the numbers from 1 to 20 sequentially
  • o It will print the numbers from 0 to 19 but the order is not determined
  • o It will print the numbers from 1 to 20 but the order is not determined
  • o It will print the numbers from 0 to 9 two times, but the order is not determined

Question 25

Question
25. [html]Which two can be used to create a new Thread? <br> 1. Extend java.lang.Thread and override the run() method <br> 2. Extend java.lang.Runnable and override the start() method <br> 3. Implement java.lang.Thread and implement the run() method <br> 4. Implement java.lang.Runnable and implement the run() method <br> 5. Implement java.lang.Thread and implement the start() method
Answer
  • o 1 and 2
  • o 2 and 3
  • o 3 and 4
  • o 4 and 5
  • o 1 and 4
  • o 2 and 5

Question 26

Question
26. The following block of code creates a Thread using a Runnable target: <br> br> Which of the following classes can be used to create the target, so that the preceding code compiles correctly?
Answer
  • o public class MyRunnable extends Runnable{public void run(){}}
  • o public class MyRunnable extends Object{public void run(){}}
  • o public class MyRunnable implements Runnable{public void run(){}}
  • o public class MyRunnable implements Runnable{void run(){}}
  • o public class MyRunnable implements Thread{void run(){}}

Question 27

Question
27. What will be the output of the program?<br>
Answer
  • o AB
  • o BC
  • o BCD
  • o ABC
  • o ACD

Question 28

Question
28. Which interface does the java.util.Hashtable implement?
Answer
  • o java.util.Map
  • o java.util.Set
  • o java.util.Collection
  • o java.util.List
  • o java.util.HashTable

Question 29

Question
29. Which of these will create and start this thread? <br>
Answer
  • o new Runnable(MyRunnable).start();
  • o new Thread(MyRunnable).run();
  • o new Thread(new MyRunnable()).start();
  • o new MyRunnable().start();
  • o new Runnable(MyRunnable).run();

Question 30

Question
30. The number of characters in an object of a class String is given by
Answer
  • o The member variable called size
  • o The member variable called length
  • o The method size() returns the number of characters
  • o The method length() returns the number of characters

Question 31

Question
31. Which of the following statements is correct?
Answer
  • o An import statement, if defined, must be the non-comment statement of the file
  • o Private members are accessible to all classes in the same package
  • o An abstract class can be declared as final
  • o Local variables cannot be declared as static

Question 32

Question
32. Which code determines the int value data closer to, but not greater than, a double value b?
Answer
  • o int data = (int)Math.ceil(b)
  • o int data = (int)Math.floor(b)
  • o int data = (int)Math.abs(b)
  • o int data = (int)Math.min(b)

Question 33

Question
33. Which statement is true for the Class java.util.HashSet?
Answer
  • o The elements in the collection are unique
  • o The elements in the collection are ordered
  • o The elements in the collection are synchronized
  • o The collection is guaranteed to be immutable

Question 34

Question
34. [html]What will be the output of the program? <i><br>class Exc0 extends Exception{} <br> class Exc1 extends Exc0 {} // Line 2 <br> public class Test { <br> public static void main(String args[]) { <br> try { <br> throw new Exc1(); //Line 9 <br> } catch (Exc0 e0) { <br> System.out.println(“Ex0 caught”); <br>} catch(Exception e) { <br> System.out.println(“Exception caught”);<br>}<br>}<br>}
Answer
  • o Ex0 caught
  • o Exception caught
  • o Compilation fails because of an error at line 2
  • o Ex0 caught Exception caught

Question 35

Question
35. Which of the following is not a part of OOP?
Answer
  • o Type checking
  • o Multitasking
  • o Polymorphism
  • o Information hiding

Question 36

Question
36. Static methods cannot be accessed directly from the class level
Answer
  • True
  • False

Question 37

Question
37. The process by which one object can acquire the properties of another object
Answer
  • o Encapsulation
  • o Inheritance
  • o Polymorphism

Question 38

Question
38. Constructors are used to
Answer
  • o Build a user interface
  • o Free memory
  • o Initialize a newly created object
  • o To create a sub class

Question 39

Question
39. What happens in a method if an exception is thrown in a try{} block and there is NO MATCHING catch{} block?
Answer
  • o This is not legal, so the program will not compile
  • o The method throws the exception to its caller, exactly if there were no try{} block
  • o The program halts immediately
  • o The program ignores the exception

Question 40

Question
40. Is a program required to catch all exceptions that might happen?
Answer
  • o No. You can write a program to catch just the exceptions you want
  • o No. But if a program catches one type of exception it must catch all other types as well
  • o Yes. If a program is not written to catch all exceptions it will not compile
  • o Yes. A program can not do I/O unless it catches all exceptions

Question 41

Question
41. What method of an Exception object returns a message string?
Answer
  • o getError()
  • o getMessage()
  • o printMessage()
  • o traceMessage()

Question 42

Question
42. What happens during execution if a negative value is used for an array index?
Answer
  • o An IndexOutOfBoundsException is thrown
  • o A NumberFormatException is thrown
  • o The first slot of the array is used
  • o This is an Error, so the program immediately terminates no matter what

Question 43

Question
43. What method of an Exception object prints a list of methods that were called before the exception was throw?
Answer
  • o printErrors()
  • o getMessage()
  • o traceStack()
  • o printStackTrace()

Question 44

Question
44. A single sequence of code executing within a program is known as:
Answer
  • o A method
  • o A process
  • o A thread

Question 45

Question
45. To start the execution of a thread after you create it, you must:
Answer
  • o Call the method run()
  • o Call the method start()
  • o Do nothing, threads start automatically upon creation
  • o Call the method notify()

Question 46

Question
46. You designate a method as being synchronized by:
Answer
  • o Using the keyword synchronized
  • o Naming the method synchronize
  • o Placing a synchronized section of code within it

Question 47

Question
47. What method is declared in the Runnable interface and serves as the path of execution for all threads?
Answer
  • o run()
  • o start()
  • o go()

Question 48

Question
48. What is a buffer?
Answer
  • o A section of memory used as a staging area for input or output data
  • o The cable that connects a data source to the bus
  • o Any stream that deals with character IO
  • o A file that contains binary data

Question 49

Question
49. What happens if a FileWriter constructor is given an illegal file name?
Answer
  • o The program bombs immediately
  • o The users disk is corrupted
  • o The constructor returns a null value
  • o An IOExcpetion is thrown

Question 50

Question
50. When a file is opened for appending where does the write() put new text?
Answer
  • o At the beginning of the file
  • o At the end of the file
  • o Where ever the user specifies
  • o Files cannot be appended to

Question 51

Question
51. A null reference may be used to access a static variable or method
Answer
  • True
  • False

Question 52

Question
52. Set allows at most two null elements?
Answer
  • True
  • False

Question 53

Question
53. Which collection class allows you to access its elements by associating sorted element and provides an order?
Answer
  • o java.util.TreeSet
  • o java.util.HashSet
  • o java.util.TreeMap
  • o java.util.Hashtable

Question 54

Question
54. A class cannot define more than one constructor
Answer
  • True
  • False

Question 55

Question
55. If you were to store objects into an implementation of List which happens only once in the entire lifecycle of the product,but reading these objects inside the List implementation is quite high, then which one would you use?
Answer
  • o Queue
  • o Stack
  • o ArrayList
  • o LinkedList

Question 56

Question
56. In java one class can derive from one class?
Answer
  • True
  • False

Question 57

Question
57. Which of the following is not true for abstract classes?
Answer
  • o Abstract class cannot to be instantiated
  • o Abstract class handlers can be used to handle derived class objects
  • o We can’t have an abstract class without abstract methods
  • o Abstract class has member elements

Question 58

Question
58. Which of the following is not true for static keyword?
Answer
  • o Static members are shared by all objects of the class
  • o We can override static methods
  • o Static methods operate only on static variables only
  • o Static elements are accessed using class name

Question 59

Question
59. List is a/an …?
Answer
  • o Class
  • o Interface
  • o Both
  • o Package

Question 60

Question
60. Which exception is thrown by the read () method of InputStream class?
Answer
  • o IOException
  • o FileNotFoundException
  • o ReadException
  • o AccessDeniedException

Question 61

Question
61. Which is the Java keyword used to denote a class method?
Answer
  • o class
  • o final
  • o private
  • o static

Question 62

Question
62. What is Recursion in Java?
Answer
  • o Recursion is a class
  • o Recursion is a process of defining a method that calls other methods repeatedly
  • o Recursion is a process of defining a method that calls itself repeatedly
  • o Recursion is a process of defining a method that calls other methods which in turn call again this method

Question 63

Question
63. Which of these data types is used by operating system to manage the Recursion in Java?
Answer
  • o Array
  • o Stack
  • o Queue
  • o Tree
  • o Map

Question 64

Question
64. What will be an output? <br>
Answer
  • o true true
  • o true false
  • o false true
  • o false false
  • o Runtime error will occur

Question 65

Question
65. What will be an output? <br>
Answer
  • o 24
  • o 30
  • o 120
  • o 720
  • o Compilation Error
  • o Runtime Error

Question 66

Question
66. What will be an output? <br>
Answer
  • o 1
  • o 0
  • o 5
  • o 15
  • o Compilation Error
  • o Runtime Error

Question 67

Question
67. What will be an output? <br>
Answer
  • o 1
  • o 0
  • o 12
  • o 78
  • o Compilation error
  • o Runtime error

Question 68

Question
68. Deletion is faster in LinkedList than ArrayList
Answer
  • True
  • False

Question 69

Question
69. Can a top level class be private?
Answer
  • True
  • False

Question 70

Question
70. Which of the following is not a primitive data type?
Answer
  • o Double
  • o int
  • o char
  • o boolean
  • o No right answer

Question 71

Question
71. The term wrapper class refers to
Answer
  • o A collection of java classes that used to make an object from primitive data types
  • o The java classes that contain at least two data fields
  • o The java classes that contain a reference to themselves
  • o A collection of java classes that contain other java classes

Question 72

Question
72. What will be the output of the program? <br>
Answer
  • o Got the exception 10
  • o Got the exception e
  • o Compilation error
  • o Runtime error

Question 73

Question
73. What will be the output of the program? <br>
Answer
  • o Got the Test Exception
  • o Inside finally block
  • o Got the Test Exception <br> Inside finally block
  • o Compilation error

Question 74

Question
74. What will be the output of the program? <br>
Answer
  • o Compilation error
  • o Compiles and runs fine
  • o Compiles fine but throws ArithmeticException at runtime

Question 75

Question
75. What will be the output of the program? <br>
Answer
  • o Caught base class exception
  • o Caught derived class exception
  • o Caught base class exception <br> Caught derived class exception
  • o Compilation error because derived is not throwable
  • o Compilation error because base class exception is caught before derived class

Question 76

Question
76. What will be the output of the program? <br>
Answer
  • o Compilation error
  • o Divide by zero error
  • o inside the finally block
  • o a = 0
  • o a=0 <br> Divide by zero block <br> inside the finally block

Question 77

Question
77. What will be the output of the program?<br>
Answer
  • o Compilation error
  • o Runtime error
  • o ArrayIndexOutOfBoundsException
  • o ErrorCode is printed
  • o Array is printed

Question 78

Question
78. Which of the following is not true about interfaces in java?
Answer
  • o An interface is similar to a class, but can contain following type of members. <br> public, static, final fields(i.e., constants) <br> default and static methods with bodies
  • o An instance of interface can be created
  • o A class can implement multiple interfaces
  • o Many classes can implement the same interface

Question 79

Question
79. Which of the following is not true about inheritance in java?
Answer
  • o Private methods are final
  • o Protected members are accessible within a package and inherited classes outside the package
  • o Protected methods are final
  • o We cannot override private methods

Question 80

Question
80. Which of the following is true about inheritance in Java. <br>1) In Java all classes inherit from the Object class directly or indirectly. The Object class is root of all classes.<br> 2) Multiple inheritance is not allowed in Java.<br>3) Inheritance is a part of polymorphism
Answer
  • o 1,2 and 3
  • o 1 and 2
  • o 1 and 3
  • o 2 and 3
  • o Only 1
  • o Only 2
  • o Only 3

Question 81

Question
81. What will be the output of the program? <br>
Answer
  • o Derived::show() called
  • o Base::show() called
  • o Compilation error
  • o Runtime error

Question 82

Question
82. What will be the output of the program? <br>
Answer
  • o Derived::show() called
  • o Base::show() called
  • o Compilation error
  • o Runtime error

Question 83

Question
83. What will be the output of the program? <br>
Answer
  • o Base
  • o Derived
  • o Compilation error
  • o Runtime error

Question 84

Question
84. What will be the output of the program? <br>
Answer
  • o Compilation error in super.super.Print()
  • o Grandparent’s print <br> Child’s Print()
  • o Grandparent’s print <br> Parent’s Print <br> Child’s Print()
  • o Runtime error

Question 85

Question
85. What will be the output of the program? <br>
Answer
  • o Complex number is (10.0 + 15.0i)
  • o Compilation error
  • o Runtime error
  • o Complex number is Complex@8e2fb5 (where 8e2fb5 is hash code of c)

Question 86

Question
86. What will be the output of the program? <br>
Answer
  • o 20
  • o 0
  • o Compilation error
  • o Runtime error

Question 87

Question
87. What will be the output of the program? <br>
Answer
  • o s1 == s2 is: true
  • o s1 == s2 is: false
  • o true
  • o false
  • o compilation error
  • o runtime exception

Question 88

Question
88. Which of the following is used by byte streams for input?
Answer
  • o InputStream
  • o InputOutputStream
  • o BufferedReader
  • o Scanner
  • o System.in

Question 89

Question
89. Which of these classes are used by character streams output operations?
Answer
  • o InputStream
  • o ReadStream
  • o Writer
  • o OutputStream

Question 90

Question
90. Which of the following is not a wrapper class?
Answer
  • o Byte
  • o String
  • o Integer
  • o Character
  • o Double
  • o Long

Question 91

Question
91. What restriction is there on using a super reference in a constructor?
Answer
  • o Only one child class can use it
  • o It can only be used in parent class
  • o It must be used in the first statement of the constructor of subclass
  • o It must be used in the last statement of the constructor of subclass
  • o No right answer

Question 92

Question
92. A method that is used to assign values to the instance variables of the class is called a
Answer
  • o set method
  • o get method
  • o accessor
  • o constructor
  • o toString() method

Question 93

Question
93. Which of the following is not a keyword for an exception handling?
Answer
  • o try
  • o catch
  • o throw
  • o thrown
  • o finally

Question 94

Question
94. Which of the following keywords is used to handle the exception by try block?
Answer
  • o try
  • o finally
  • o catch
  • o throw
  • o throws

Question 95

Question
95. Which of these operator is used to generate an instance of an exception than can be thrown by using throw?
Answer
  • o new
  • o malloc
  • o alloc
  • o thrown
  • o return

Question 96

Question
96. Which of the followings is a type of stream in java?
Answer
  • o Integer stream
  • o Byte stream
  • o Short stream
  • o Long stream

Question 97

Question
97. What will be the output of the following program? <br>
Answer
  • o BD
  • o ABDE
  • o BCDE
  • o BCD
  • o BDE
  • o ABCE
  • o ABCD
  • o ABD

Question 98

Question
98. What will be the output of the following code? <br>
Answer
  • o hello caught finally after
  • o hello throwit finally
  • o hello throwit caught finally after
  • o hello caught after
  • o compilation fails
  • o caught finally after

Question 99

Question
99. What will be the output of the program? <br>
Answer
  • o finally
  • o Compilation fails
  • o exception finished
  • o finally finished
  • o finally exception finished
  • o finally exception

Question 100

Question
100. What will be the output of the program? <br>
Answer
  • o ABCD
  • o ACD
  • o ABD
  • o BCD
  • o BC
  • o BD
  • o CD

Question 101

Question
101. What will be the output of the program? <br>
Answer
  • o Hello world
  • o Hello world Finally executing
  • o Finally executing
  • o Nothing. The program will not compile because no exceptions are specified
  • o Nothing. The program will not compile because no catch clauses are specified

Question 102

Question
102. What will be the output of the program? <br>
Answer
  • o Ex0 caught
  • o Exception caught
  • o Compilation fails on line 2
  • o Compilation fails on line 9
  • o Compilation fails on line 11

Question 103

Question
103. Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
Answer
  • o java.util.HashSet
  • o java.util.List
  • o java.util.LinkedHashSet
  • o java.util.ArrayList
  • o java.util.HashMap
  • o java.util.Map

Question 104

Question
104. You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?
Answer
  • o java.util.Map
  • o java.util.List
  • o java.util.Set
  • o java.util.Collection

Question 105

Question
105. Which interface does java.util.Hashtable implement?
Answer
  • o java.util.Map
  • o java.util.List
  • o java.util.HashTable
  • o java.util.Set
  • o java.util.Collection

Question 106

Question
106. Which interface provides the capability to store objects using a key-value pair?
Answer
  • o java.util.Map
  • o java.util.List
  • o java.util.HashTable
  • o java.util.Set
  • o java.util.Collection

Question 107

Question
107. What line of code should replace the missing statement to make this program compile? <br>
Answer
  • o import java.io.*;
  • o import java.io.PrintWriter
  • o include java.io.*;
  • o no statement required

Question 108

Question
108. What is the numerical range of char?
Answer
  • o 0 .. 32767
  • o 0 .. 65535
  • o -256 .. 255
  • o 0 .. 255
  • o -32768 .. 32767
  • o 0 .. 511

Question 109

Question
109. In Java, defining more than one method having the same name within a particular class is called
Answer
  • o overloading
  • o sharing
  • o overriding
  • o superseding

Question 110

Question
110. What is an inheritance?
Answer
  • o It is the process where one object acquires the properties of another
  • o Inheritance is the ability of an object to take on many forms
  • o Inheritance is a technique to define different methods of same types
  • o None of the above.

Question 111

Question
111. When constructor is called?
Answer
  • o Constructor is called before creating the object
  • o Constructor is called after creating the object
  • o Constructor is called concurrently when object creation is going on
  • o Constructor cannot be called

Question 112

Question
112. What is the difference between a try-catch block and a try-catch-finally block?
Answer
  • o try-catch contains code to execute whether an occurs or not, try-catch-finally contains code to execute only if an error occurs
  • o try-catch contains code to execute if an error occurs or not, while try-catch-finally works the same way as try-catch block with the addition of a set of code that will execute whether an error occurs or not
  • o Same thing, different names
  • o try-catch contains code to execute only if an error occurs, try-catch-finally contains code to execute whether an occurs or not

Question 113

Question
113. Which keyword would you use if you wanted a class to use an interface?
Answer
  • o implements
  • o extends
  • o throws
  • o new
  • o main()

Question 114

Question
114. Which keyword would you use to break out of a loop?
Answer
  • o break
  • o continue
  • o while
  • o for
  • o do

Question 115

Question
115. What will be the output of this code? <br><html> <i>String a = “Crayons are great!”; <br> System.out.println(a.charAt(8));</i></html>
Answer
  • o r
  • o n
  • o s
  • o a
  • o e

Question 116

Question
116. Which package is imported by default into Java programs?
Answer
  • o java.awt
  • o java.awt.font
  • o java.lang
  • o java.io
  • o java.util

Question 117

Question
What is the purpose of a class constructor?
Answer
  • o To make objects initially have certain values when they are instantiated
  • o To extend a class
  • o To pass values to methods for a class
  • o To instantiate an object

Question 118

Question
117. What will be the output of the program?<br>
Answer
  • o 0
  • o error
  • o Compilation fails
  • o An uncaught exception is thrown at runtime
  • o No output
  • o / by 0

Question 119

Question
118. Given : <br> <b>-A and E are classes <br>-B and D are interfaces<br>-C is an abstract class <br></b> Which is true?
Answer
  • o class F implements B,C
  • o class F implements C
  • o class F extends A,C
  • o class F implements E
  • o class F extends C implements B
  • o class F extends B

Question 120

Question
119. Given <br> <br> <b> Note: The keyword "instanceof" is use to check whether an object is of a particular type</b><br>What is the result?
Answer
  • o Compilation fails due to error at line 3
  • o Will produce output as false
  • o Compilation fails due to error at line 4
  • o Length of this array is 3
  • o Will produce output a true

Question 121

Question
120. What will be the output? <br>
Answer
  • o Got the Test Exception<br> Inside finally block
  • o Inside finally block
  • o Got the Test Exception
  • o Compilation fails

Question 122

Question
121. What will be the output? <br>
Answer
  • o Caught base class exception
  • o Caught derived class exception
  • o Compiler error because derived is not throwable
  • o Compiler error because base class exception is caught before derived class

Question 123

Question
122. A java array that contains N components will be indexed from ….. through …..
Answer
  • o 0, N – 1
  • o 1, N
  • o 0, N
  • o 1, N - 1

Question 124

Question
123. Which method must exist, to make your class executable?
Answer
  • o main
  • o begin
  • o init
  • o int
  • o paint

Question 125

Question
124. What will be output produced after the execution of the following code segment? <br>String name = “Elvis”; <br> System.out.println(name + “was here”);
Answer
  • o Elviswas here
  • o Elvis was here
  • o namewas here
  • o name was here
  • o name + was here

Question 126

Question
125. What will be output produced after the execution of the following code segment? <br>int x = 5; <br> int y = 2; <br> System.out.println(x + “1“ + y);
Answer
  • o 512
  • o 5 1 2
  • o 8
  • o The code will cause a compilation error

Question 127

Question
126. What will be output produced after the execution of the following code segment? <br>int x = 5; <br> int y = 2; <br> System.out.println(x + y + “1“);
Answer
  • o 71
  • o 521
  • o 5 2 1
  • o 7 1
  • o The code will cause a compilation error
  • o All are valid

Question 128

Question
127. What will be the result of the following code segment? <br>
Answer
  • o 2 4 6 8
  • o 2 4 6 8 10
  • o 2 4 6 8 10 1 3 5 7 9
  • o 1 3 5 7 9
  • o 9 7 5 3 1 10 8 6 4 2

Question 129

Question
128. What is the output of the following code segment?
Answer
  • o A
  • o B
  • o C
  • o D or lower

Question 130

Question
129. If you want to execute body at least once, what type of loop would you use?
Answer
  • o for loop
  • o while loop
  • o none of the given
  • o do .. while loop

Question 131

Question
130. What are the values of I and product after this code is executed? <br>
Answer
  • o 9 and 366
  • o 9 and 336
  • o 8 and 42
  • o 8 and 336

Question 132

Question
131. What is the output of the following code fragment? <br>
Answer
  • o Error
  • o 2 times Hello
  • o 3 times Hello
  • o No output will be produced

Question 133

Question
132. What is the purpose of the semicolon mark (;) in a Java program?
Answer
  • o Designates a temporary separation when used in a package statement.
  • o It is used once and only once in a program
  • o Designates the end of a statement or unit of Java code.
  • o It is used only with JApplet class.
  • o It is an optional end-of-file marker

Question 134

Question
133. What is the size of short variable?
Answer
  • o 8 bit
  • o 16 bit
  • o 32 bit
  • o 64 bit

Question 135

Question
134. Which of the following is true about public access modifier?
Answer
  • o Variables, methods and constructors which are declared public can be accessed by any class.
  • o Variables, methods and constructors which are declared public can be accessed by any class lying in same package
  • o Variables, methods and constructors which are declared public in the superclass can be accessed only by its child class
  • o No right answer

Question 136

Question
135. Which of the following is not a keyword in Java?
Answer
  • o static
  • o void
  • o Boolean
  • o private

Question 137

Question
136. Which of the following stands true about default modifier of class members?
Answer
  • o By default, variables, methods and constructors can be accessed by subclass only.
  • o By default, variables, methods and constructors can be accessed by any class lying in any package.
  • o By default, variables, methods and constructors can be accessed by any class lying in the same package.
  • o No right answer

Question 138

Question
137. Inheritance represents
Answer
  • o HAS-A relationship
  • o IS-A relationship

Question 139

Question
138. What is function overloading?
Answer
  • o Methods with same name but different parameters.
  • o Methods with same name but different return types
  • o Methods with same name, same parameter types but different parameter names.
  • o No right answer

Question 140

Question
139. What is a class in java?
Answer
  • o A class is a blue print from which individual objects are created. A class can contain fields and methods to describe the behavior of an object
  • o class is a special data type
  • o class is used to allocate memory to a data type.
  • o No right answer

Question 141

Question
140. Can be constructor be made private?
Answer
  • True
  • False

Question 142

Question
141. What is JRE?
Answer
  • o JRE is a java based GUI application.
  • o JRE is an application development framework
  • o JRE is an implementation of the Java Virtual Machine which executes Java programs
  • o No right answer

Question 143

Question
142. What is essential in making sure that your loop is not infinite?
Answer
  • o That your Boolean statement at some point will be false
  • o That your Boolean statement at some point will be true
  • o That there is a Boolean statement somewhere in your code
  • o All answers are right

Question 144

Question
143. In a “for” loop, what section is not included in parentheses after “for”?
Answer
  • o Initialization
  • o Loop body
  • o Test statement
  • o Update

Question 145

Question
144. Abstract method can be in
Answer
  • o abstract class
  • o normal class
  • o concrete class
  • o any class

Question 146

Question
145. One or more function that has different number of arguments or different type of arguments but all have the same return type is called as
Answer
  • o Method overriding
  • o Method overloading
  • o Inheritance
  • o Encapsulation

Question 147

Question
146. Static variables cannot be accessed directly from the class level
Answer
  • True
  • False

Question 148

Question
147. When a class is based on another class, it inherits:
Answer
  • o The data and methods for the class
  • o The methods and messages for the class
  • o Only the data for the class
  • o Static block of that class

Question 149

Question
148. When sub class declares a method that has the same type arguments as a method in the parent class, it is termed as
Answer
  • o Method overriding
  • o Method overloading
  • o Operator overloading
  • o Operator overriding

Question 150

Question
149. Constructors are used to
Answer
  • o Build a user interface
  • o Free memory
  • o Initialize a newly created object
  • o To create a sub class

Question 151

Question
150. What is a template, or specification, that determines a type of object in java?
Answer
  • o A class
  • o A template
  • o A struct
  • o A prototype
  • o A framework

Question 152

Question
151. The process by which one object can acquire the properties of another object?
Answer
  • o Encapsulation
  • o Inheritance
  • o Polymorphism
  • o Aggregation

Question 153

Question
152. What is the highest index value is associated with the array that follows? <br> <i> byte[] values = new byte[x]; </i>
Answer
  • o 0
  • o x
  • o x+1
  • o x-1

Question 154

Question
153. which of the following statements gets the number of integers in the array that follows? <br> <i> int[] customers = new int[55];</i>
Answer
  • o int size = customers.length();
  • o int size = customers.size();
  • o int size = costomers.length;
  • o int size = Arrays.size(customers);
  • o int size = Arrays.length(customers);

Question 155

Question
154. What will be the output of the following code? <i> <br> int[] arr = new int[9]; <br> System.out.println(arr[9]);</i>
Answer
  • o 0
  • o Some junk value
  • o Error because array is not initialized
  • o Error because index out of range

Question 156

Question
155. When an object no longer has any reference variables referring to it, what happens to the object?
Answer
  • o It sits around in main memory forever
  • o It is swapped out the disk
  • o It is sent to the Dumpster
  • o The garbage collector makes the memory it occupies available for new objects

Question 157

Question
156. What value is assigned to a reference value to show that there is no object?
Answer
  • o 0
  • o null
  • o void
  • o 0x00000
  • o “”

Question 158

Question
158. Which one of the below shows the correct use of public to modify a method?
Answer
  • Public Void init()
  • public class MyProgram()
  • void public init()
  • public int myMethod()
  • init() public void

Question 159

Question
159.Which statement is accurate for the use of void with a method?
Answer
  • The void keyword means that the method will not return a value.
  • The void keyword denotes a particular instance of the void class.
  • The void method returns a void data type.
  • The void keyword means that the statements in the method are not executed.
  • This keyword voids the effects of a method.

Question 160

Question
160. Which of the below shows the correct form of a method? public int void goodBye() { code here }
Answer
  • public void MyProgram() { code here}
  • public voided hello() { code here } public
  • intGoodBye();
  • private int goodBye() {code here }

Question 161

Question
161. Which of the following is the closing brace for a block of statements in a method?
Answer
  • [
  • {
  • ]
  • }
  • ()

Question 162

Question
162. If a class has one method in it, which of the following would be the last two symbols in the program?
Answer
  • {}
  • ))
  • }}
  • )}
  • }{

Question 163

Question
163. Given the line, public class MyTextArea extends JTextArea {, which of the following statements is correct?
Answer
  • JTextArea is a subclass of MyTextArea.
  • MyTextArea is a superclass of the extends class.
  • MyTextArea is a subclass of the JText class.
  • JTextArea is a superclass of MyTextArea.
  • JTextArea is a class of MyTextArea.

Question 164

Question
164. What will be the output of the program?<br>
Answer
  • 0 1 2
  • 0 1 2 1 2 2
  • 2 1 0 1 0 0
  • 2 1 2 0 1 2
  • 2 1 2 1 0 2

Question 165

Question
165. What will be the output of the program?<br>
Answer
  • XyZabc
  • XyZABC
  • xyzabc
  • abcXyZ
  • abcxyz

Question 166

Question
166. Which of the following will directly stop the execution of a Thread?
Answer
  • wait()
  • notifyAll()
  • notify()
  • exits synchronized code

Question 167

Question
167. What will be the output of the program? <br>
Answer
  • It compiles and runs printing nothing It
  • compiles but fails at runtime
  • Compile error
  • It compiles and runs printing “complete”

Question 168

Question
168. What allows the programmer to destroy an object x? x.delete();
Answer
  • x.destroy();
  • x.clean();
  • Runtime.getRuntime.gc(x);
  • Only the garbage collection system can destroy the object

Question 169

Question
169. Information hiding can also be termed as
Answer
  • Data hiding
  • Encapsulation
  • Inheritance
  • Data minding

Question 170

Question
170. Two or more functions with same name in the same class with different arguments is called as
Answer
  • Method overriding
  • Method overloading
  • Encapsulation

Question 171

Question
171. When sub class declares a method that has the same type arguments as a method declared by one of its superclass it is termed as
Answer
  • Method overriding
  • Method overloading
  • Operator overriding
  • Operator overloading

Question 172

Question
172. What does closing file do?
Answer
  • Flushes pending output and finishes processing the file
  • Finishes processing the file, only
  • Flushes pending output, but the file may still be written to
  • Makes the file read-only

Question 173

Question
173. What method ensures that data from previous calls to write() is sent to disk and leaves the file open?
Answer
  • flush()
  • close()
  • each write() does this for the previous one.
  • print()

Question 174

Question
174. If a file opened for reading does not exist, which of the following events will occur in Java?
Answer
  • A run-time error will occur
  • A NullPointerException will be rised
  • A FileNotFoundException will be rised
  • A new file will be created

Question 175

Question
175. If a file opened for writing does not exist, which of the following events will occur in Java?
Answer
  • A NullPointerException will be rised
  • A run-time error will occur
  • A FileNotFoundException will be rised
  • A new file will be created

Question 176

Question
176. If a class contains a constructor, that constructor will be invoked
Answer
  • Each time an object of that class is instantiated
  • Each time an object of that class goes out of scope
  • Once at the beginning of any program that uses that class
  • Each time a method of an object of that class is invoked

Question 177

Question
177. In Java, the default layout manager for a JFrame component is
Answer
  • a) GridLayout
  • b) FlowLayout
  • c) GridingLayout
  • d) BorderLayout

Question 178

Question
178. Linked list cannot be implemented by using arrays
Answer
  • True
  • False

Question 179

Question
179. Can stack be described as a pointer?
Answer
  • True
  • False

Question 180

Question
180. What is the signature of the method specified in the Java ActionListener interface?
Answer
  • a) void actionPerformed (ActionListener al)
  • c) void actionListener (ActionEvent ae)
  • b) void actionEvent (ActionPerformed ap)
  • d) void actionPerformed (ActionEvent ae)

Question 181

Question
181. How many String objects have been created? String x = new String("xyz"); String y = "abc"; x = x + y;
Answer
  • a) 1
  • b) 2
  • c) 3
  • d) 4

Question 182

Question
182. Which of the following is a Java event that is generated when a JButton component is pressed?
Answer
  • a) ButtonEvent
  • b) WindowEvent
  • c) ClickEvent
  • d) ActionEvent

Question 183

Question
183. Which one is true declaration? 1 final abstract class Test {} 2 public static interface Test {} 3 final public class Test {} 4 protected abstract class Test {}
Answer
  • 1
  • 2
  • 3
  • 4

Question 184

Question
184. What is the keyword in java used to create an instance?
Answer
  • a) this
  • b) object
  • d) none of the above
  • c) new

Question 185

Question
185. You can create java project same as:
Answer
  • a) public class name
  • c) any name
  • b) Main.java
  • d) class name

Question 186

Question
186. Consider following coding: public class Object1 { protected String d(){ return "Hi"; }} public class Object2 extends Object1 { protected String d(){ return super.d(); }} Which of the following statements are true regarding the definitions? Class Object2 inherits from class Object1. Class Object2 overrides method d. Method d do not returns equivalent results when executed from either class.
Answer
  • a) III
  • b) I, II, and III
  • c) I and III
  • d) I and II

Question 187

Question
187. What will be the output the following method Java code import java.io.IOException class Animal { public void eat() throws IOException { } } class Dog extends Animal { public void eat() throws IOException { } }
Answer
  • a) Compilation error at Line 8
  • b) Compilation error at Line 7
  • c) Compilation error at Line 6
  • d) successful compilation

Question 188

Question
188. What will be the output the following method Java code import java.io.*; public class Test { public Test( ) { System.out.println("default"); } public Test( int i ) { System.out.println("non-default"); } public static void main(String[] args) { Test t = new Test(2); } }
Answer
  • a) The line of text "non-default" followed by the line of text "default"
  • b) The line of text "default"
  • c) The line of text "default" followed by the line of text "non-default"
  • d) The line of text "non-default"

Question 189

Question
189. The name of a Java source file.
Answer
  • a) has no restrictions
  • b) must be the same as the class it defines, respecting case
  • c) must be the same as the class it defines, ignoring case
  • d) must use the extension .class

Question 190

Question
190. The ActionEvent class and ActionListener interface are available in the _____ package of Java.
Answer
  • a) javax.swing.event
  • b) java.awt.event
  • c) javax.event
  • d) java.event

Question 191

Question
191. If a class has an association with itself, then the class contains
Answer
  • a) its own superclass
  • b) an attribute that references an object of the same class
  • c) a method that calls itself
  • d) a method that calls another method within the same class

Question 192

Question
192. What will be the output? class Equals { public static void main(String [] args) { int x = 100; double y = 100.1; boolean b = (x = y); System.out.println(b); } }
Answer
  • a) 100
  • c) 100.1
  • b) compilation error
  • d) true

Question 193

Question
193. In Java, what is the signature of the method in the WindowListener interface where code is to be added to end a program when the close button is pressed?
Answer
  • a) void windowClosing (WindowEvent we)
  • b) void windowClosed (WindowEvent we)
  • c) void windowDeactivated (WindowEvent we)
  • d) void windowAdapter (WindowEvent we)

Question 194

Question
194. Which of the following implementation will you use if you were to insert elements at any position in the collection ??
Answer
  • a) Vector
  • b) List
  • c) LinkedList
  • d) ArrayList

Question 195

Question
195. An empty list is the one which has no
Answer
  • a) data
  • b) nodes
  • c) a and b
  • d)address

Question 196

Question
196. JVM stands for
Answer
  • a) Java Verify Machine
  • b) Java Visual Machine
  • d) Java Virtual Machine
  • c) Java Visual Member

Question 197

Question
197. Which of the following is not the method of object class?
Answer
  • a) toString
  • c) finalize
  • b) clone
  • d) system

Question 198

Question
198. Which of the following is True about final keyword
Answer
  • a) We can declare abstract class as final.
  • b) We can modify final variables.
  • c) We can't declare a class abstract as well as final.
  • d) We can override final methods.

Question 199

Question
199. Which of the following is false about collections in Java ?
Answer
  • b) java.util is the default package for collection classes.
  • a) List , Map and Set are interfaces.
  • c) Collection interface is the base interface.
  • d) List , Map and Set are abstract classes

Question 200

Question
200. Which of the following is not true for hashtable and hasmaps ?
Answer
  • a) Hashtable are synchronized whereas hashmaps are not.
  • b) Hashtable doesn't allow null values whereas HashMaps allows null values.
  • c) Hashtable came before Hashmap
  • d) HashMaps are synchronized whereas hashtables are not.
Show full summary Hide full summary

Similar

Timeline of World War One
amayagn
Mechanics
james_hobson
GCSE Geography Climate Change
EllieFlint
Biology 1 Keeping Healthy Core GCSE
Chloe Roberts
The English Language Techniques
craycrayley
med chem 2
lola_smily
ENZYMES AND THE DIGESTIVE SYSTEM
ashiana121
What is Marketing?
Stephanie Natasha
Functionalist Theory of Crime
A M
Dr Jekyll and Mr Hyde THEMES
deanakentish
English Language Techniques 2
Adam Arrell