Core Java Interview Questions – Set 13

Why main() in java is declared as public static void main? What if the main method is declared as private?

Public – main method is called by JVM to run the method which is outside the scope of project therefore the access specifier has to be public to permit call from anywhere outside the application static – When the JVM makes are call to the main method there is not object existing for the class being called therefore it has to have static method to allow invocation from class. void – Java is platform independent language therefore if it will return some value then the value may mean different to different platforms so unlike C it can not assume a behavior of returning value to the operating system. If main method is declared as private then – Program will compile properly but at run-time it will give “Main method not public.” error.

What is the difference between Array and vector?-

Array is a set of related data type and static whereas vector is a growable array of objects and dynamic.

What is the difference between scrollbar and scrollpane

A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling.

What restrictions are placed on method overloading?

Two methods may not have the same name and argument list but different return types.

Which Component subclass is used for drawing and painting

Canvas.

How many ways can an argument be passed to a subroutine and explain them?-

An argument can be passed in two ways. They are passing by value and passing by reference. Passing by value: This method copies the value of an argument into the formal parameter of the subroutine. Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.

What value does readLine() return when it has reached the end of a file?

The readLine() method returns null when it has reached the end of a file.

What is the difference between superclass and subclass?-

?– A super class is a class that is inherited whereas sub class is a class that does the inheriting.

What is an abstract class?-

An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete

What is the difference between the >> and >>> operators?

The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.