ServiceNow Core Java Interview Questions Answers

ServiceNow Most Frequently Asked Latest Core Java Interview Questions Answers

What Is A Pointer And Does Java Support Pointers?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.

What Is The Base Class Of All Classes?

java.lang.Object

Does Java Support Multiple Inheritance?

Java doesn't support multiple inheritance.

Is Java A Pure Object Oriented Language?

Java uses primitive data types and hence is not a pure object oriented language.
ServiceNow Most Frequently Asked Latest Core Java Interview Questions Answers
ServiceNow Most Frequently Asked Latest Core Java Interview Questions Answers

Are Arrays Primitive Data Types?

In Java, Arrays are objects.

What Is Difference Between Path And Classpath?

Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.

What Are Local Variables?

Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.

What Are Instance Variables?

Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.

How To Define A Constant Variable In Java?

The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also. static final int PI = 2.14; is an example for constant.

Should A Main Method Be Compulsorily Declared In All Java Classes?

No not required. main method should be defined only if the source class is a java application.

What Is The Return Type Of The Main Method?

Main method doesn't return anything hence declared void.

Why Is The Main Method Declared Static?

main method is called by the JVM even before the instantiation of the class hence it is declared as static.

What Is The Arguement Of Main Method?

main method accepts an array of String object as arguement.

Can A Main Method Be Overloaded?

Yes. You can have any number of main methods with different method signature and implementation in the class.

Can A Main Method Be Declared Final?

Yes. Any inheriting class will not be able to have it's own default main method.

Does The Order Of Public And Static Declaration Matter In Main Method?

No it doesn't matter but void should always come before main().

Can A Source File Contain More Than One Class Declaration?

Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.

What Is A Package?

Package is a collection of related classes and interfaces. package declaration should be first statement in a java class.

Which Package Is Imported By Default?

java.lang package is imported by default even without a package declaration.

Can A Class Declared As Private Be Accessed Outside It's Package?

Not possible.

Can A Class Be Declared As Protected?

A class can't be declared as protected. only methods can be declared as protected.

What Is The Access Scope Of A Protected Method?

A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.

What Is The Purpose Of Declaring A Variable As Final?

A final variable's value can't be changed. final variables should be initialized before using them.

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.

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.

Post a Comment

Previous Post Next Post