December 22, 2018

Srikaanth

Globant Most Frequently Asked Core Java Interview Questions Answers

What Is The Importance Of Static Variable?

static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.

Can We Declare A Static Variable Inside A Method?

Static variables are class level variables and they can't be declared inside a method. If declared, the class will not compile.

What Is An Abstract Class And What Is It's Purpose?

A Class which doesn't provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction.

Can A Abstract Class Be Declared Final?

Not possible. An abstract class without being inherited is of no use and hence will result in compile time error.

What Is Use Of A Abstract Variable?

Variables can't be declared as abstract. only classes and methods can be declared as abstract.

Can You Create An Object Of An Abstract Class?

Not possible. Abstract classes can't be instantiated.

Can A Abstract Class Be Defined Without Any Abstract Methods?

Yes it's possible. This is basically to avoid instance creation of the class.
Globant Most Frequently Asked Core Java Interview Questions Answers
Globant Most Frequently Asked Core Java Interview Questions Answers

Class C Implements Interface I Containing Method M1 And M2 Declarations. Class C Has Provided Implementation For Method M2. Can I Create An Object Of Class C?

No not possible. Class C should provide implementation for all the methods in the Interface I. Since Class C didn't provide implementation for m1 method, it has to be declared as abstract. Abstract classes can't be instantiated.

Can A Method Inside A Interface Be Declared As Final?

No not possible. Doing so will result in compilation error. public and abstract are the only applicable modifiers for method declaration in an interface.

Can An Interface Implement Another Interface?

Intefaces doesn't provide implementation hence a interface cannot implement another interface.

Can An Interface Extend Another Interface?

Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.

Can A Class Extend More Than One Class?

Not possible. A Class can extend only one class but can implement any number of Interfaces.

Why Is An Interface Be Able To Extend More Than One Interface But A Class Can't Extend More Than One Class?

Basically Java doesn't allow multiple inheritance, so a Class is restricted to extend only one Class. But an Interface is a pure abstraction model and doesn't have inheritance hierarchy like classes(do remember that the base class of all classes is Object). So an Interface is allowed to extend more than one Interface.

Can An Interface Be Final?

Not possible. Doing it will result in compilation error.

Can A Class Be Defined Inside An Interface?

Yes it's possible.

Can An Interface Be Defined Inside A Class?

Yes it's possible.

What Is A Marker Interface?

An Interface which doesn't have any declaration inside but still enforces a mechanism.

Which Oo Concept Is Achieved By Using Overloading And Overriding?

Polymorphism.

If I Only Change The Return Type, Does The Method Become Overloaded?

No it doesn't. There should be a change in method arguements for a method to be overloaded.

Why Does Java Not Support Operator Overloading?

Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn't support operator overloading.

Can We Define Private And Protected Modifiers For Variables In Interfaces?

No

What Is Externalizable?

Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in).

Subscribe to get more Posts :