Share on Google+Share on Google+

Core Java Interview Question, Interview Question

This page discusses - Core Java Interview Question, Interview Question

Core Java Interview Question Page 25


Question: What are null or Marker interfaces in Java

Answer: The null interfaces are marker interfaces, they do not have function declarations in them, they are empty interfaces, this is to convey the compiler that they have to be treated differently

Question: Does java Support multiple inheritance

Answer: Java does not support multiple inheritance directly like C++, because then it is prone to ambiguity, example if a class extends 2 other classes and these 2 parent classes have same method names then there is ambiguity. Hence in Java Multiple inheritance is supported using Interfaces

Question: What are virtual function 

Answer: In OOP when a derived class inherits from a base class, an object of the derived class may be referred to (or cast) as either being the base class type or the derived class type. If there are base class functions overridden by the derived class, a problem then arises when a derived object has been cast as the base class type. When a derived object is referred to as being of the base's type, the desired function call behavior is ambiguous.

The distinction between virtual and not virtual is provided to solve this issue. If the function in question is designated "virtual" then the derived class's function would be called (if it exists). If it is not virtual, the base class's function would be called.

Question: Does java support virtual functions

Answer: No java does not support virtual functions direclty like in C++, but it supports using Abstract class and interfaces

Question: Describe what happens when an object is created in Java

Answer: Several things happen in a particular order to ensure the object is constructed properly:

1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the
object and its superclasses. Implemenation-specific data includes pointers to class and method data.

2. The instance variables of the objects are initialized to their default values.

3. The constructor for the most derived class is invoked. The first thing a constructor does is call the
consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called,
as java.lang.Object is the base class for all objects in java.

4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks
are executed. Then the body of the constructor is executed. Thus, the constructor for the base class
completes first and constructor for the most derived class completes last.

Question: What is the purpose of System Class

Answer: The purpose of the system class is to provide the access to the System reources

Question: What is instanceOf operator used for

Answer: It is used to if an object can be cast into a specific type without throwing Class cast exception

Question: Why we should not have instance variable in an interface

Answer: Since all data fields and methods in an Interface are public by default, then we implement that interface in our class then we have public members in our class and this class will expose these data members and this is violation of encapsulation as now the data is not secure

Question: What is JVM

Answer: When we install a java package. It contains 2 things
* The Java Runtime Environment (JRE)
* The Java Development Kit (JDK)

The JRE provides runtime support for Java applications. The JDK provides the Java compiler and other development tools. The JDK includes the JRE.

Both the JRE and the JDK include a Java Virtual Machine (JVM). This is the application that executes a Java program. A Java program requires a JVM to run on a particular platform

Question: Can abstract class be final

Answer: No, abstract class cannot be final

Question: When a new object of derived Class is created, whose constructor will be called first, childs or parents

Answer: Even when the new object of child class is created, first the Base class constructor gets executed and then the child classes constructor

Question: What is a singleton class

Answer: A singleton is an object that cannot be instantiated. The restriction on the singleton is that there can be only one instance of a singleton created by the Java Virtual Machine (JVM) - by prevent direct instantiation we can ensure that developers don't create a second copy.

Question: Can an abstract class have final method

Answer: Yes

Question: Can a final class have an abstract method

Answer: No, the compiler will give an error

Question: What is the difference between Authentication and Authorization

Answer: Authentication is a process for verifying that an individual is who they say they are. Authorization is an additional level of security, and it means that a particular user (usually authenticated), may have access to a particular resource say record, file, directory or script.


Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

November 30, 2011
core java