elibraryportal Logo

1) Give the list of Java Object class methods

The Java Object class methods are .

  1. toString() :- Returns a string representation of the object.
  2. getClass() :- Returns the runtime class of an object.
  3. hashCode() :- Returns a hash code value for the object.
  4. clone() : - Creates and returns a copy of this object.
  5. equals() :- Indicates whether some other object is "equal to" this one.
  6. finalize() :- Called by the garbage collector on an object when garbage collection
  7. determines that there are no more references to the object.
  8. wait() :- Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
  9. notify() :- Wakes up a single thread that is waiting on this object's monitor.
  10. notifyAll() :- Wakes up all threads that are waiting on this object's monitor.

2) Can Java thread object invoke start method twice ?

No, it throws IllegalThreadStateException

3) Can we override static method ?

You cannot override static methods. Because Static methods are belongs to class, not belongs to object.

4) Can you list serialization methods ?

Serialization interface does not have any methods. serialization is a marker interface.

5) What is the difference between super() and this() ?

this and super are two special keywords in Java,

(1) in Java , this represents current instance of a class, while super represent current instance of the parent class.

(2) super() is used to call super class constructor, whereas this() used to call constructors in the same class, means to call parameterized constructors.

6) Can we create abstract classes without any abstract methods?

Yes, we can create abstract classes without any abstract methods.

7) How to destroy the session in servlets?

we can destory the session, By calling invalidate() method on session object.

8) Can we have static methods in interface?

By default, all methods in an interface are decleared as public, abstract. It will never be static. Java 8 came with new feature called "default methods" with in interfaces.

9) What is transient variable?

transient keyword is used in serialization. If you define any data member as transient, it will not be serialized. transient variable in Java is a variable whose value is not serialized during Serialization and which is initialized by its default value during de-serialization, for example for object transient variable it would be null.

Next Topic