SDP3
Which two can be used to create a new Thread? 1. Extend java.lang.Thread and override the run() method 2. Extend java.lang.Runnable and override the start() method 3. Implement java.lang.Thread and implement the run() method 4. Implement java.lang.Runnable and implement the run() method 5. Implement java.lang.Thread and implement the start() method
1 and 4
Which of the following is true about inheritance in Java. 1) In Java all classes inherit from the Object class directly or indirectly. The Object class is root of all classes. 2) Multiple inheritance is not allowed in Java. 3) Inheritance is a part of polymorphism
1,2 and 3
Which of the following statements about the hashcode() method are incorrect? 1.The value returned by hashcode() is used in some collection classes to help locate objects 2. The hashcode() method is required to return a positive int value 3. The hashcode() method in the String class is the one inherited from Object 4. Two new empty String objects will produce identical hashcodes
2 and 3
1. The default constructor initialises method variables. 2. The default constructor has the same access as its class. 3. The default constructor invokes the no-arg constructor of the superclass. 4. If a class lacks a no-arg constructor, the compiler always creates a default constructor. 5. The compiler creates a default constructor only when there are no other constructors for the class.
2,3,5
If a file opened for reading does not exist, which of the following events will occur in Java?
A FileNotFoundException will be rised
What is a template, or specification, that determines a type of object in java?
A class
If a file opened for writing does not exist, which of the following events will occur in Java?
A new file will be created
Java uses call by value. What is the value that is being passed into the routine by the method call in the following? double rats[] = {1.2 , 2.3, 3.4}; routine(rats);
A reference of the array
A single sequence of code executing within a program is known as:
A thread
Which of the following is a Java event that is generated when a JButton component is pressed?
ActionEvent
What happens if a FileWriter constructor is given an illegal file name?
An IOExcpetion is thrown
What happens during execution if a negative value is used for an array index?
An IndexOutOfBoundsException is thrown
Which of these will happen if recursive method does not have a base case?
An infinite loop occurs
Which of the following is not true about interfaces in java?
An instance of interface can be created
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?
ArrayList
When a file is opened for appending where does the write() put new text?
At the end of the file
In Java, the default layout manager for a JFrame component is
BorderLayout
Parent of all collection classes is a/an ....?
Both
Which of the following can be used for implementing runtime polymorphism ?
Both
Which of the following has member elements?
Both
Which of the followings is a type of stream in java?
Byte stream
To start the execution of a thread after you create it, you must:
Call the method start()
When constructor is called?
Constructor is called concurrently when object creation is going on
If a class contains a constructor, that constructor will be invoked
Each time an object of that class is instantiated
A class cannot define more than one constructor
False
Set allows at most two null elements?
False
Static variables cannot be accessed directly from the class level
False
What does closing file do?
Flushes pending output and finishes processing the file
Which of the following is not true for hashtable and hasmaps ?
HashMaps are synchronized whereas hashtables are not.
Which exception is thrown by the read () method of InputStream class?
IOException
Which exception is thrown by the read() method of InputStream class?
IOException
The process by which one object can acquire the properties of another object
Inheritance
The process by which one object can acquire the properties of another object?
Inheritance
Which of the following is used by byte streams for input?
InputStream
What is an inheritance?
It is the process where one object acquires the properties of another
Given the line, public class MyTextArea extends JTextArea {, which of the following statements is correct?
JTextArea is a superclass of MyTextArea.
Which of the following implementation will you use if you were to insert elements at any position in the collection ??
LinkedList
Which of the following is false about collections in Java
List , Map and Set are abstract classes
Which of the following statements is correct?
Local variables cannot be declared as static
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
Method overloading
Two or more functions with same name in the same class with different arguments is called as
Method overloading
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
Method overriding
When sub class declares a method that has the same type arguments as a method in the parent class, it is termed as
Method overriding
What is function overloading?
Methods with same name but different parameters.
Is a program required to catch all exceptions that might happen?
No. You can write a program to catch just the exceptions you want
Which class or interface defines the wait(), notify(),and notifyAll() methods?
Object
Which of the following is not true about inheritance in java?
Protected methods are final
Which of these is not a correct statement?
Recursion is managed by Java's run time environment.
Which of these data types is used by operating system to manage the Recursion in Java?
Stack
Which of the following is not a wrapper class?
String
When a class is based on another class, it inherits:
The data and methods for the class
Which statement is true for the Class java.util.HashSet?
The elements in the collection are unique
When an object no longer has any reference variables referring to it, what happens to the object?
The garbage collector makes the memory it occupies available for new objects
The number of characters in an object of a class String is given by
The method length() returns the number of characters
What is the purpose of a class constructor?
To make objects initially have certain values when they are instantiated
A null reference may be used to access a static variable or method
True
Can be constructor be made private?
True
In java one class can derive from one class?
True
You designate a method as being synchronized by:
Using the keyword synchronized
Which of the following is true about public access modifier?
Variables, methods and constructors which are declared public can be accessed by any class.
Which of the following is True about final keyword
We can declare abstract class as final.
Which of the following is not true for static keyword?
We can override static methods
Which of the following is not true for abstract classes?
We can't have an abstract class without abstract methods
Which of these classes are used by character streams output operations?
Writer
If a class has an association with itself, then the class contains
an attribute that references an object of the same class
What is the keyword in java used to create an instance?
c) new
Which of the following keywords is used to handle the exception by try block?
catch
Given : A and E are classes B and D are interfaces C is an abstract class Which is true?
class F extends C implements B
Can a top level class be private?
false
Linked list cannot be implemented by using arrays
false
Static methods cannot be accessed directly from the class level
false
What method ensures that data from previous calls to write() is sent to disk and leaves the file open?
flush()
Which keyword would you use if you wanted a class to use an interface?
implements
Which of these packages contains the exception Stackoverflow in Java?
java.lang
Which package is imported by default into Java programs?
java.lang
Which interface does java.util.Hashtable implement?
java.util.Map
Which interface does the java.util.Hashtable implement?
java.util.Map
Which interface provides the capability to store objects using a key-value pair?
java.util.Map
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?
java.util.Set
Which collection class allows you to access its elements by associating sorted element and provides an order?
java.util.TreeSet
Which of these operator is used to generate an instance of an exception than can be thrown by using throw?
new
In Java, defining more than one method having the same name within a particular class is called
overloading
What method of an Exception object prints a list of methods that were called before the exception was throw?
printStackTrace()
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?
private
Which is a Java access modifier used to designate that a particular data field will not be inherited by a subclass?
private
You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
protected
Which of the below shows the correct form of a method? public int void goodBye() { code here }
public void MyProgram() { code here}
What method is declared in the Runnable interface and serves as the path of execution for all threads?
run()
Which is the Java keyword used to denote a class method?
static
What is the signature of the method specified in the Java ActionListener interface?
void actionPerformed (ActionEvent ae)
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?
void windowClosing (WindowEvent we)
Which of the following is the closing brace for a block of statements in a method?
}
If a class has one method in it, which of the following would be the last two symbols in the program?
}}