MultiThreading

1.Explain multithreading,multitasking and multiprocessing?
Ans:
2.What is Live Lock in threading,explain with real example.
Answer: A husband and wife are trying to eat soup, but only have one spoon between them. Each spouse is too polite, and will pass the spoon if the other has not yet eaten is an example of live lock.
here husband and wife can be consider as two thread and spoon is resource.

Object Oriented Programming Language in Java

Q1.What is polymorphism? Is there any relation between Overloading/Overriding and Polymorphism?
Ans:The word ‘polymorphism(poly means many + morphism means behavior)’ so literally polymorphism means ‘a state of many behaviour’.

When applied to object oriented programming languages like Java, it describes a language’s ability to process objects of various types and classes through a single, uniform interface.

Polymorphism in Java has two types: Compile time polymorphism (static binding) and Runtime polymorphism (dynamic binding). Method overloading is an example of static polymorphism, while method overriding is an example of dynamic polymorphism.


Q2. UpCasting and dowcasting.
Ans:Class A{}
Class B extends A{
}

Lets say, Class A varA;
Class B varB;

varA=new A(); //Correct
varA=new B(); //Correct
varB=new B(); //Correct
var = new A(); // Incorrect
how to resolve the above one
 you need to downcast a super class to subclass.

varB=(varB) new A(); //Correct now