Object class - Java test
1) In object class parent class reference variable can refer the child class object, known as?
A) Upcasting
B) Implicit casting
C) Explicit casting
D) Boolean casting
View Answer / Hide Answer2) Which method compares the given object to this object?
A) public boolean equals(Object obj)
B) public final void notifyAll()
C) public final void notify()
D) public final ClassgetClass()
View Answer / Hide AnswerANSWER: A) public boolean equals(Object obj)
3) Which method causes the current thread to wait for the specified milliseconds, until another thread notifies? (invokes notify() or notifyAll() method)?
A) public final void wait(long timeout)throws InterruptedException
B) protected void finalize()throws Throwable
C) public final void wait(long timeout,int nanos)throws InterruptedException
D) protected Object clone() throws CloneNotSupportedException
View Answer / Hide AnswerANSWER: A) public final void wait(long timeout)throws InterruptedException
4) The object cloning is a way to create exact copy of an object?
A) True
B) False
View Answer / Hide Answer5) The clone() method is defined in?
A) Abstract class
B) Object Class
C) ArrayList class
D) None of the above
View Answer / Hide Answer6) Which method of object class can clone an object?
A) copy()
B) Objectcopy()
C) Objectclone()
D) Clone()
View Answer / Hide Answer7) Which is an acronym for, it physically exists; it contains JRE + development tools?
A) JRE
B) JVM
C) JDK
D) None of the above
View Answer / Hide Answer8) The JDK forms an extended subset of a software development kit (SDK)?
A) True
B) False
View Answer / Hide Answer9) In which the standard collection classes implements a linked list data structure?
A) LinkedList
B) AbstractList
C) HashSet
D) Both B & C
View Answer / Hide Answer10) Which extends the AbstractList class and implements List and Deque interfaces?
A) AbstractList
B) LinkedList
C) HashSet
D) None of the above
View Answer / Hide Answer11) Generally string is a sequence of characters, But in java, string is an
A) Object
B) Class
C) Package
D) None of the above
View Answer / Hide Answer12) In which string class function returns the number of characters in a string?
A) length()
B) replace()
C) charAt()
D) equalIgnoreCase()
View Answer / Hide Answer13) String class in encapsulated under which package?
A) java.lang
B) java.util
C) java.io
D) java.awt
View Answer / Hide Answer14) Java defines a peer class of String, called?
A) StringBuffer
B) StringBuilder
C) Both A & B
D) None of the above
View Answer / Hide Answer15) Which concept is used to make Java more memory efficient (because no new objects are created if it exists already in string constant pool)?
A) String literal
B) By new keyword
C) Both A & B
D) None of the above
View Answer / Hide AnswerANSWER: A) String literal
16) Which method of string class in java Returns a new string that is a substring of this string?
A) public String substring(int beginIndex,int endIndex)
B) public String substring(int beginIndex)
C) public boolean equalsIgnoreCase(String another)
D) Both A & B
View Answer / Hide Answer17) Which method of string class in java is used to converts the boolean into String?
A) public static String valueOf(double i)
B) public static String valueOf(boolean i)
C) public boolean equals(Object anObject)
D) public static String valueOf(Object obj)
View Answer / Hide AnswerANSWER: B) public static String valueOf(boolean i)
18) A pool of strings, initially empty, is maintained privately by the class String?
A) intern() method
B) length() method
C) trim() method
D) charAt() method
View Answer / Hide AnswerANSWER: A) intern() method
19) The following program is an example of?
class Simple{
public static void main(String args[]){
String s="Sachin";
System.out.println(s.length());//6
}
}
A) length() method
B) intern() method
C) trim() method
D) charAt() method
View Answer / Hide AnswerANSWER: A) length() method
20) Which class is thread-safe i.e. multiple threads cannot access it simultaneously,So it is safe and will result in an order?
A) StringBuffer class
B) StringBuilder class
C) Both A & B
D) None of the above
View Answer / Hide AnswerANSWER: A) StringBuffer class
21) Which constructor creates an empty string buffer with the specified capacity as length.
A) StringBuffer()
B) StringBuffer(String str)
C) StringBuffer(int capacity)
D) None of the above
View Answer / Hide AnswerANSWER: C) StringBuffer(int capacity)
22) This method of StringBuffer Class is used to insert the specified string with this string at the specified position?
A) public synchronized StringBuffer append(String s)
B) public synchronized StringBuffer insert(int offset, String s)
C) public String substring(int beginIndex)
D) public int length()
View Answer / Hide AnswerANSWER: B) public synchronized StringBuffer insert(int offset, String s)
23) By overriding the toString() method of the Object class, we can return values of the object, so we don't need to write much code?
A) True
B) False
View Answer / Hide Answer24) How many constructors are defined in StringTokenizer class?
A) 2
B) 3
C) 4
D) 5
View Answer / Hide Answer25) The Object class is not a parent class of all the classes in java by default?
A) True
B) False
View Answer / Hide Answer