Object class - Java test

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 Answer

ANSWER: A) Upcasting




2) 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 Answer

ANSWER: 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 Answer

ANSWER: 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 Answer

ANSWER: A) True




5) The clone() method is defined in?

A) Abstract class
B) Object Class
C) ArrayList class
D) None of the above
View Answer / Hide Answer

ANSWER: B) Object Class




6) Which method of object class can clone an object?

A) copy()
B) Objectcopy()
C) Objectclone()
D) Clone()
View Answer / Hide Answer

ANSWER: C) Objectclone()




7) 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 Answer

ANSWER: C) JDK




8) The JDK forms an extended subset of a software development kit (SDK)?

A) True
B) False
View Answer / Hide Answer

ANSWER: A) True




9) 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 Answer

ANSWER: A) LinkedList




10) 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 Answer

ANSWER: B) LinkedList




11) 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 Answer

ANSWER: A) Object




12) In which string class function returns the number of characters in a string?

A) length()
B) replace()
C) charAt()
D) equalIgnoreCase()
View Answer / Hide Answer

ANSWER: A) length()




13) String class in encapsulated under which package?

A) java.lang
B) java.util
C) java.io
D) java.awt
View Answer / Hide Answer

ANSWER: A) java.lang




14) Java defines a peer class of String, called?

A) StringBuffer
B) StringBuilder
C) Both A & B
D) None of the above
View Answer / Hide Answer

ANSWER: A) StringBuffer




15) 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 Answer

ANSWER: 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 Answer

ANSWER: D) Both A & B




17) 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 Answer

ANSWER: 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 Answer

ANSWER: 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 Answer

ANSWER: 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 Answer

ANSWER: 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 Answer

ANSWER: 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 Answer

ANSWER: 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 Answer

ANSWER: A) True




24) How many constructors are defined in StringTokenizer class?

A) 2
B) 3
C) 4
D) 5
View Answer / Hide Answer

ANSWER: B) 3




25) The Object class is not a parent class of all the classes in java by default?

A) True
B) False
View Answer / Hide Answer

ANSWER: B) False



Post your comment

    Discussion

  • RE: Object class - Java test -JavaCrazy (10/09/15)
  • A few more questions have wrong answers.
  • RE: Object class - Java test -JavaGuru (10/09/15)
  • nice!!!
  • RE: Object class - Java test -Anupriya (10/09/15)
  • The answer to the question "Which method of object class can clone an object?" is wrong . The correct answer is "clone()" and not "öbjectCone()" . Please get it corrected .