Fresher Java Interview Questions in Auromine Solutions – Part – I

Fresher Java Interview Questions in Auromine Solutions – Part – I

This blog explains about Fresher Java Interview Questions in Auromine Solutions – Part – I . Some of them are discussed below :

_______________________________________________________________________________________

 1.  What is different between interface and multiple inheritance ?

Inheritance in simple terms is to acquire the properties / behaviours of an other class. In order to achieve Inheritance we have to use a keyword extends in JAVA.

Example:

Interface Car

{ public void display(); //Incomplete Method, Method has no Implementation.

}

class B implements Car

{ public void display()

{ System.out.println(“HI”);

} }

Here display method is over-rided and completed in class B. Hence no need to declare class B as abstract.

_______________________________________________________________________________

2. What is different between interface and abstract ?

Interfaces

An interface is a contract: The person writing the interface says, “hey, I accept things looking that way“, and the person using the interface says “OK, the class I write looks that way“.

An interface is an empty shell. There are only the signatures of the methods, which implies that the methods do not have a body. The interface can’t do anything. It’s just a pattern.

For example (pseudo code):

// I say all motor vehicles should look like this:

interface MotorVehicle

{

    void run();

     int getFuel();

}

 // My team mate complies and writes vehicle looking that way

class Car implements MotorVehicle

{

     int fuel;

     void run()

    {

        print(“Wrroooooooom”);

    }

      int getFuel()

    {

        return this.fuel;

    }

}

______________________________________________________________________________

3 . What are the rules for method overriding ? 

If any possible to declare Method overriding in same class 

Rules for method overriding:

  • In java, a method can only be written in Subclass, not in same class.
  • The argument list should be exactly the same as that of the overridden method.
  • The return type should be the same or a subtype of the return type declared in the original overridden method in the super class.
  • The access level cannot be more restrictive than the overridden method’s access level.
    • For example: if the super class method is declared public then the over-ridding method in the sub class cannot be either private or protected.
  • Instance methods can be overridden only if they are inherited by the subclass.
  • A method declared final cannot be overridden.
  • method declared static 
  • cannot be overridden but can be re-declared.
  • If a method cannot be inherited then it cannot be overridden.
  • A subclass within the same package as the instance’s super class can override any super class method that is not declared private or final.
  • A subclass in a different package can only override the non-final methods declared public or protected.
  • An overriding method can throw any un check exceptions, regardless of whether the overridden method throws exceptions or not.
    • However the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw narrower or fewer exceptions than the overridden method.
  • ___________________________________________________________________________