Polymorphism is the ability of an object to take on many forms. Any java object that can pass more than one IS-A test is considered to be polymorphic-Supertype : A class or interface is a supertype relative to another type, if its corresponding class or interface has been extended or implemented directly or indirectly by the class or interface of other type.Subtype : A class or  interface is subtype relative to another type, if its corresponding class or interface is directly or indirectly extending or implementing to the class of other type.POLYMORPHISM TYPESCompile Time(Static polymorphism)This type of polymorphism is resolved during compiler time. Method overloading is an example of compile time polymorphism. Method overloading allows us to have multiple methods having the same name if the parameters inside are different.Runtime (Dynamic polymorphism)Also known as Dynamic Method Dispatch, Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime. Declaring a method in subclass which is already present in parent class is known as method overriding. Overriding is done so that the child can give implementations to the method provided by the parent class.Parametric PolymorphismSay we have some list of items, those items are of not the same type, but different ones (there are integers, doubles, strings, and characters). Now consider creating a method head() that returns only the first item in the list. The method doesn’t care if it’s a string, or integers, or any type. Its return type is the one list is parameterized with and its implementation is the same for all types : “return first item”. Parametric polymorphism applies to one of OOP’s technique “generics”.Ad Hoc PolymorphismUnlike parametric polymorphism, ad hoc polymorphism is bound to a type. Depending on the type, different implementations of the method are invoked. Again, method overloading is one example of Ad Hoc Polymorphism. For Example, you can have two version of method that appends two items. One takes two integers and adds them, and one takes two strings and concatenates them.

An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.Use abstract class if:You want to share code among several closely related classes..You expect that classes that extend your abstract class have many common methods or fields, or require access modifiers other than public (such as protected and private)..You want to declare non static or non final fields. This enables you to define methods that can access and modify the state of the object to which they belong.Use interfaces if:You expect that unrelated classes would implement your interface.i.e.the interfaces Comparable and Cloneable are implemented by many unrelated classes..You want to specify the behaviour of a particular data type but not concerned about who implements its behaviour..You want to take advantage of multiple inheritance of type.DifferencesType of methodsInterface can only have abstract methods, while abstract class can have abstract and non abstract methodsFinal VariablesVariables declared in java interface are by default final. An abstract class may contain non-final variablesType of variablesabstract class can have final, non-final, static, and non-static variables. Interface has only static and final variablesImplementationabstract class can provide the implementation of interface. Interface cannot provide the implementation of abstract class.Inheritance vs abstractionA java interface can be implemented using keyword “implements” and abstract class can be extended using keyword “extends”Multiple implementationAn interface can extend another java interface only, an abstract class can extend another java class and implement multiple java interfacesAccessibility of Data MembersMembers of  a Java interface are public by default. A java abstract class can have class members like private, protected, etc.

states of threads new thread When a new thread is created, its in the new state. The thread has not yet started to run when in this state, and code is yet to be run and hasn’t started to execute runnableA thread that is ready to run is moved to the runnable state. The thread might actually be running or ready to run in an instant in this stateblocked/waiting stateThis is when a thread is temporarily inactive. Thread in this state cannot continue its execution unless being moved to the runnable state. Any thread in this state does not consume any CPU cycle. If a currently running thread is moved to a blocked/waiting state, another thread in the runnable state is scheduled by thread scheduler to runtimed waitingA thread is in the timed waiting state when it calls a method with a time out parameter. For example when a thread calls sleep or a conditional wait, then it is moved to timed waiting stateterminated stateA thread terminates because of either of the following reasons:Because it exits normally (when the code of thread  has entirely been executed by the program)/Because there was some unusual erroneous event, like unhandled exceptionConcurrency vs ParallelismConcurrency occurs when tasks that are running look simultaneously, but actually they may not. They take advantage of CPU time-slicing feature where each task run part of its task and then go to the waiting state. When first task is at waiting task, the CPU is assigned to second task to complete its part of task. So in concurrency, tasks run in overlapping time periods. All in all, concurrency makes programs run like they’re in parallel, but essentially they don’t.Parallelism literally run parts of tasks or multiple tasks, all in the same time using multi-core infrastructure CPU by assigning one core to each task or sub-task. Parallelism requires hardware with multiple processing unit. In a single core CPU, you may get concurrency but not parallelism