Sunteți pe pagina 1din 2

What is use of synchronized keyword? Ans: - This keyword is used to prevent concurrency.

Synchronized keyword can be applied to static/non-static methods or a block of code. Only one thread at a time can access synchronized methods and if there are multiple threads trying to access the same method then other threads have to wait for the execution of method by one thread. Synchronized keyword provides a lock on the object and thus prevents race condition. ______________________________________________________________________________ What is a static variable? Ans: - Static keyword can be used with the variables and methods but not with the class but there are static class. Anything declared as static is related to class and not objects. Static variable: Multiples objects of a class shares the same instance of a static variable. ______________________________________________________________________________ Does java support multiple interitance? Ans: - Java doesnt support multiple inheritance but it provide a way through which it can enact it. This problem in java is taken care with the use of interfaces ______________________________________________________________________________ What is polymorphism? Ans: - Polymorphism gives us the ultimate flexibility in extensibility. The ability to define more than one function with the same name is called Polymorphism. There are two type of polymorphism: compile time polymorphism (overloading) and runtime polymorphism (overriding). ______________________________________________________________________________ What is inheritance? Ans: - Inheritance is the property which allows a Child class to inherit some properties from its parent class. ______________________________________________________________________________ What is abstraction? Ans: - Abstraction is way of converting real world objects in terms of class. For example creating a class Vehicle and injecting properties into it ______________________________________________________________________________

What is encapsulation? Ans: - The encapsulation is achieved by combining the methods and attribute into a class. The class acts like a container encapsulating the properties. The users are exposed mainly public methods. The idea behind is to hide how things work and just exposing the requests a user can do. ______________________________________________________________________________ What are the different states of a thread's lifecycle? Ans: - 1) New When a thread is instantiated it is in New state until the start() method is called on the thread instance. In this state the thread is not considered to be alive. 2) Runnable The thread enters into this state after the start method is called in the thread instance. The thread may enter into the Runnable state from Running state. In this state the thread is considered to be alive. 3) Running When the thread scheduler picks up the thread from the Runnable threads pool, the thread starts running and the thread is said to be in Running state. 4)Waiting/Blocked/Sleeping In these states the thread is said to be alive but not runnable. The thread switches to this state because of reasons like wait method called or sleep method has been called on the running thread or thread might be waiting for some i/o resource so blocked. 5)Dead When the thread finishes its execution i.e. the run() method execution completes, it is said to be in dead state. A dead state can not be started again. If a start() method is invoked on a dead thread a runtime exception will occur. ______________________________________________________________________________ What's the difference between constructors and other methods? Ans: - Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

______________________________________________________________________________

S-ar putea să vă placă și