Saturday, December 3, 2011

Some Of Basic FAQ about Core JAVA


Hi Friends,

In this blog i want to share some of basic FAQ about Core JAVA that may help you have some basic information.

  1. Can multiple inheritance be achieved in Java. If yes, how?
    Answer – Yes, through implementing interfaces as we can implemente multile interfaces in a single class.
  2. What is the basic difference between String and StringBuffer object?
    Answer - String is an immutable object. StringBuffer is a mutable object.
  3. What is the base class for Error and Exception?
    Answer – Throwable is base class for Exception.
  4. What is a static block?
    Answer – this is the block executed before the class initialization.
  5. Can static methods call directly non static methods of the same class?
    Answer – No. They cannot directly call. If they need, they will have to create object.
  6. From an overridden method of the sub class, how can you call the overridden base class method ?
    Answer – call the method by using 'super' keyword.
  7. Can protected methods be accessed by classes in different package.
    Answer – Yes, provided they are subclasses. Otherwise no.
  8. Can a subclass reference hold a superclass object.
    Eg: Class A, Class B.
    If B extends A. Can we say B b = new A()
    Answer – No. Viceversa is true (if A a = new B() is fine).
  9. If a super class method is throwing an IOException, what should the overriding sub class method throw?
    Answer – It should either
    Throw the same IOException
    Throw a sub class of IOException.
    Throw nothing
  10. What are the two ways of making a class non-extensible?
    Make the class Final
    Make the constructor private

No comments: