Friday 23 August 2013

Java Interview Questions And Answers

I have made every effort in writing this post to ensure accuracy of the information. In this section you can find all commonly asked Java interview question with their answers.  I am sure it will help you a lot. If you have any suggestion about these Java Question & Answer please write to us.


Here Questions and their Answers are arranged in a systematic manner so that you can learn it with ease. 

Q1: What is Abstract Class?
 A1: A class that contains one or more abstract methods, and therefore can never be instantiated, but rather inherited by other classes.

Q2: What is Abstract Method?
A2: A method that has no implementation.

Q3: What do you mean by Encapsulation?
A3: Encapsulation refers to keeping all the variables and methods together in an object. Because objects encapsulate data and implementation, the user of an object can view the object as a black box that provides services.

Q4: Give a few reasons for using Java?
A4: 1) Java is Object Oriented, 2) Platform independent, 3) Built in support for multi-threading, socket communication, memory management, 4) Supports web based applications like Applet, Servlet and JSP.

Q5: What is an Argument?
A5: A data item specified in a method call. An argument can be a literal value, a variable, or an expression.

Q6: What is difference between C++ and Java?
A6: 1) Java does not support pointer, 2) Java does not support multiple inheritance, 3) Java does not support global variables or functions as all the Java program is encapsulated within class while C++ supports global variables and functions and 4) Java includes automatics garbage collection while C++ requires explicit memory management.

Q7: What is Polymorphism?
A7: Polymorphism means the ability of a single variable of a given type to be used to reference objects of different types, and automatically call the method that is specific to the type of object the variable reference.

Q8: What is Exception in Java?
A8: An event during program execution that prevents the program from continuing normally. Exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist.  

Q9: What is an Error?

A9: An Error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. Typical Java Programs should not catch Errors.

Q10: What are checked exceptions?
A10: Checked exceptions are those which the Java compiler forces you to catch. e.g. IOException are checked Exceptions.

Q11: What are runtime exceptions?
A11: Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc.

Q12: What is Exception handler?
A12: Exception handler is a block of code that reacts to a specific type of exception.

Q13: What is the difference between declaring a variable and defining a variable?
A13: In declaration we just mention the type of the variable and its name, we do not initialize it. But defining means declaration of variable as well as initialization of the variable. For example integer i ; is just a declaration while integer i = 5;  is definition.

Q14: Can a top level class be private or protected?
A14: A top level class cannot be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access.

Q15: What do you mean by a Super Class?
A15: A class from which a particular class is derived from.



4 comments:

  1. Thanks for this wonderful Q & A. Please post some more questions on java and SQL

    ReplyDelete
  2. Very helpful, thanks, haider sir

    ReplyDelete