Hi Friends,
In this blog i want to share some of basic FAQ about Core JAVA that may help you have some basic information.
In this blog i want to share some of basic FAQ about Core JAVA that may help you have some basic information.
- 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.
- What is the basic difference between String and StringBuffer object?
Answer - String is an immutable object. StringBuffer is a mutable object.
- What is the base class for Error and Exception?
Answer – Throwable is base class for Exception.
- What is a static block?
Answer – this is the block executed before the class initialization.
- 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.
- 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.
- Can protected methods be accessed by classes in different package.
Answer – Yes, provided they are subclasses. Otherwise no.
- 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).
- 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
- What are the two ways of making a class non-extensible?
Make the class Final
Make the constructor private
No comments:
Post a Comment