j1. Can we declare an anonymous class as both extending a class and implementing an interface? A 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?
A 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?
A 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?
A 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
A 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?
A 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 ?
A 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?
A 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 ?
A By using this() reference.
10. How can you call the constructor of super class ?
A By using super() syntax.
2. What are the differences between Boolean & operator and & operator?
A 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?
A 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?
A 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
A 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?
A 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 ?
A 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?
A 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 ?
A By using this() reference.
10. How can you call the constructor of super class ?
A By using super() syntax.
0 comments:
Post a Comment