Java Interview Questions - Question Set 2

Thursday, September 23, 2010

Java Interview Questions 

1. Can we declare an anonymous class as both extending a class and implementing an interface?
Ans. No. An anonymous class can extend a class or implement an interface, but it cannot be declared to do both

2. What are the differences between Boolean & operator and & operator?
Ans. When an expression containing the & operator is evaluated, both operands are evaluated. And the & operator is applied to the operand. When an expression containing && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then only the second operand is evaluated otherwise the second part will not get executed. && is also called short cut and.

3. What is the use of the finally block?
Ans. Finally is the block of code that executes always. The code in finally block will execute even if an exception is occurred. Finally will not execute when the user calls System.exit().

4. What is an abstract method?
Ans. An abstract method is a method that don’t have a body. It is declared with modifier abstract.

5. what is a the difference between System.err and System.out
Ans. We can redirect System.out to another file but we cannot redirect System.err stream

6. What are the differences between an abstract class and an interface?
Ans. An abstract class can have concrete method, which is not allowed in an interface. Abstract class can have private or protected methods and variables and only public methods and variables are allowed in interface. We can implement more than one interface, but we can extend only one abstract class. Interfaces provides loose coupling where as abstract class provides tight coupling.

7. What is the difference between synchronized block and synchronized method ?
Ans. Synchronized blocks place locks for the specified block where as synchronized methods place locks for the entire method.

8. How can you force garbage collection in java?
Ans. You cannot force Garbage Collection, but you can request for it by calling the method System.gc(). But it doesn’t mean that Garbage Collection will start immediately. The garbage collection is a low priority thread of JVM.

9. How can you call a constructor from another constructor ?
Ans. By using this() reference.

10. How can you call the constructor of super class ?
Ans. By using super() syntax.


Post a Comment

Free Website templateswww.seodesign.usFree Flash TemplatesRiad In FezFree joomla templatesAgence Web MarocMusic Videos OnlineFree Wordpress Themeswww.freethemes4all.comFree Blog TemplatesLast NewsFree CMS TemplatesFree CSS TemplatesSoccer Videos OnlineFree Wordpress ThemesFree CSS Templates Dreamweaver
This post confirms my ownership of the site and that this site adheres to Google AdSense program policies and Terms and Conditions: ca-pub-0558527597907982 nitin jain a 24 c.c colony opp r.p bagh delhi