Que1: What is difference between Process and Thread?
Ans: Process and threads are methods to get parallel execution of an application. A process have its own address space, where multiple thread can execute, It means a process can have multiple threads in it. Multiple process can interact with each others only by Inter process communication mechanism thus Inter process communication is always expensive but inter thread communication is cheap. As two process uses separate memory spaces thus if one process dies it never affects other process, but if one thread gets corrupt then other thread(and sometimes corresponding process) will get die.
Que2: What are abstract classes?
Ans: Class that contains one or more methods which are only declared not defined.In other words Abstract class is class which have one or more abstract methods(Method without body). We can not have any object of abstract class.But it can be sub classed, and that subclass have to implement all abstract methods else this subclass too have to declare as abstract class. Abstract class can be used to refer an object reference, so that at run time we can decide which method of subclass to execute.
Que3: What is an interface?
Ans: Interface is an abstract class with all abstract methods. Interface is generally defined to show a contract that any class implementing this interface will implement methods in it.
Note: Syntax for both abstract class and interface is different. The definition given it only for understanding.
Que4: What is the difference abstract class and interface?
Ans: In Abstract class contains one or many abstract methods but an interface have only abstract methods. A class can be a subclass of only one abstract class, but a class can implement one or many interfaces. Interface is a way to achieve multiple inheritance.
Que5: What is overriding?
Ans: When method name and its parameters (signature) are same in sub and super class but its definition is different. it is called as overriding.
Que6: What is overloading?
Ans: Method with same name and different signature in same class, is called method overloading.
Que7: What are different ways to block a thread in Java?
Ans: There are 3 ways:
Sleep(): thread will be blocked for specific amount of time.
Suspend(): thread need to use resume() to return back.
wait(): thread need to use notify() to return back.
Que8: What is JAR file?
Ans: JAR file is a kind of zip file for Java application containing application or libraries in the form of classes and associated meta data and resources.
Que9: What is the difference between "==" and .equals() method?
Ans: "==" compares object reference only but .equals compares its fields. Generally to compare any 2 objects use .equals method not "==".
Que10: What is the difference between constructor and methods?
Ans: Constructor has same name as class name, no other method can have name as class name. Constructor has no return type, not even void. constructor may or may not be explicitly defined for any class, Java does provide a default constructor.
For example,
public class abc{
int i;
public static void main(String args[])
{
abc h1 = new abc();
System.out.println("this works");
}
}
This works.
But if we gave abc h1=new abc(5); then it gives error that constructor not specified.
No comments:
Post a Comment