27 June 2013

Core Java Interview Questions

Hello Friends, Nice to see you again.
After lots of post related to Java Swing, Here, I come with core java part for Question and Answers.
This is not something new that you will see.
But I had always used other websites and blogs to read this stuff.
Now, I think I should also share this with others.
So enjoy this post.

Questions on OOPS Concepts

1.   What are the principle concepts of OOPS? 

           There are four principle concepts upon which object oriented design and
            programming rest. They are:
            (i.e. easily remembered as PIE).

2.    What is Encapsulation?     

            Encapsulation is a technique used for hiding the properties and 
            behaviors of an object and allowing outside access only as 
            appropriate. It prevents other objects from directly altering or 
            accessing the properties or methods of the encapsulated object.

3.     What is Inheritance?

            Inheritance is the process by which objects of one class acquire 
            the properties of objects of another class. 
            A class that is inherited is called a superclass.
            The class that does the inheriting is called a subclass.
            Inheritance is done by using the keyword extends.
            The two most common reasons to use inheritance are:
            1. To promote code reuse
            2. To use polymorphism

4.      What is Polymorphism?

            Polymorphism is briefly described as "one interface, many
            Polymorphism is a characteristic of being able to assign a different
            meaning or usage to something in different contexts - specifically, 
            to allow an entity such as a variable, a function, or an object to 
            have more than one form.

5.      What is run-time polymorphism or dynamic method dispatch?

            In Java, run-time polymorphism or dynamic method dispatch is 
            a process in which a call to an overridden method is resolved 
            at run-time rather than at compile-time.
                   In this process, an overridden method is called through the 
            reference variable of a superclass. The determination of the method 
            to be called is based on the object being referred to by the reference 

6.     What is method overloading?

            Method Overloading means to have two or more methods with same
            name in the same class with different arguments. The benefit of
            method overloading is that it allows you to implement methods
            that support the same semantic operation but differ by argument
            number or type.
            Overloaded methods MUST change the argument list
            Overloaded methods CAN change the return type
            Overloaded methods CAN change the access modifier
            Overloaded methods CAN declare new or broader checked exceptions
            A method can be overloaded in the same class or in a subclass

7.     What is method overriding?

             Method overriding occurs when sub class declares a method that has 
             the same type arguments as a method declared by one of its 
             The key benefit of overriding is the ability to define behavior that’s 
             specific to a particular subclass type.
              *     The overriding method cannot have a more restrictive access 
              modifier than the method being overridden (Ex: You can’t override 
              a method marked public and make it protected).
              *     You cannot override a method marked final
              *     You cannot override a method marked static.  

8.      Is it possible to override the main method?