Java Interview Questions On Classes, Objects and Access Specifiers |
15. Explain About the 'synchronized' Modifier?
Answer:
Applies to
- l Methods
- l Block of code
This controls the access to a piece of critical code in a multithreaded environment.
Note: It is illegal to have two access modifiers in a single declaration. But we can have along with access modifier, non-access modifier. |
16. How we declare the java Constructors?
Answer
- In Java constructor is used to initialize the object. The name of the constructor should be same name as
- the class name.
- Constructor does not return any value, and even we cannot use void as a return type.
- When you create an instance of a class, a default constructor provided by the compiler ( i.e. no
- argument constructor).
|
17. What are all the method overriding conditions?
- l Must have the same method name.
- l Must have same return type.
- l Must have same argument list.
|
18. A static modifier is valid for?
[a] Class declarations.
[b] Class static initialization blocks.
[c] Local variables.
[d] Inner classes
Answer
[b] Class static initialization blocks.
[d] Inner classes |