May 10, 2019

Srikaanth

Intuit Core Java Interview Questions Answers

What Is The Impact Of Declaring A Method As Final?

A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.

I Don't Want My Class To Be Inherited By Any Other Class. What Should I Do?

You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.

Can You Give Few Examples Of Final Classes Defined In Java Api?

java.lang.String,java.lang.Math are final classes.

How Is Final Different From Finally And Finalize?

final is a modifier which can be applied to a class or a method or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed.

finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment.

finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.

Can A Class Be Declared As Static?

No a class cannot be defined as static. Only a method,a variable or a block of code can be declared as static.
Intuit Most Frequently Asked Latest Core Java Interview Questions Answers
Intuit Most Frequently Asked Latest Core Java Interview Questions Answers

When Will You Define A Method As Static?

When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.

What Are The Restriction Imposed On A Static Method Or A Static Block Of Code?

A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.

I Want To Print "hello" Even Before Main Is Executed. How Will You Acheive That?

Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main method. And it will be executed only once.

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.

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)

What Modifiers Are Allowed For Methods In An Interface?

Only public and abstract modifiers are allowed for methods in interfaces.

What Is A Local, Member And A Class Variable?

Variables declared within a method are "local" variables. Variables declared within the class i.e not within any methods are "member" variables (global variables). Variables declared within the class i.e not within any methods and are defined as "static" are class variables.

What Is An Abstract Method?

An abstract method is a method whose implementation is deferred to a subclass.

Subscribe to get more Posts :