Define the marker interface in java ?
Interfaces with no methods are known as marker interfaces for example: Clonable, Serializable, Event listener, SingleThreadModel. These interfaces are implemented by the classes or their super classes.
What are the major reasons to use interface in java ?
There are mainly three reasons:
1.It is used to achieve fully abstraction.
2.It can support the functionality of multiple inheritance.
3.It can be used to achieve loose coupling.
Define the term Constructor in java ?
It is a specific type of method that is used to initialize the object.
What are the rules for creating constructor ?
There are primarily two rules defined for the constructor they are-
1. Constructor name must be same as its class name.
2. Constructor must have no explicit return type.
Name the types of constructors in java ?
There are two types of constructors:
1.Default constructor (no-arg constructor).
2.Parameterized constructor
Define default Constructor ?
A constructor which have no parameter is known as default constructor
Define parameterized constructor ?
A constructor which have parameters is known as parameterized constructor.
Does constructor return any value ?
Yes, that is current class instance.
When the object is to be destroyed which function is used to perform some action ?
finalize().
Which method having same name as that of its class ?
Constructor.
Write a code to print.
1
12
123
1234
12345
by using array.
[code lang=”java”]
public class MyClass {
public static void main(String[] args) {
final int max =5;
for (int row = 1; row <= max; row++) {
for (int col = 1; col <= row; col++)
System.out.print(col);
System.out.println();
}
}}
[/code]
Output:
1
12
123
1234
12345
Write a code to find max value of an array.
[code lang=”java”]
import java.util.Arrays;
public class MyClass {
public static void main(String[] args) {
int a[] = {2,6,3,7,9};
Arrays.sort(a);
int max= a[a.length-1];
System.out.println(max);
}
}
[/code]
Output:
9
Differentiate between continue statement and break statement ?
To end the current loop iteration and return the current loop statement a continue statement is used whereas in the case of break statement it results in the termination of the statement to which it applies.
Name the high level thread states ?
Ready, running, waiting and dead are the high level thread states.
Name the immediate superclass of the Applet class ?
Panel.
Does &&= a valid java operator ?
No.
Name the two Java IDE’s ?
Netbeans, Eclipse, etc.
Name some Java keywords ?
Some Java keywords are import, default, for, eum , goto, super, finally, etc.
What is a File class ?
File class provide access to the files and directories of a local file system.
Does java allow default arguments ?
No.
By using overloading and overriding which object oriented concept is achieved ?
Polymorphism.
Is an Interface be final ?
No, doing so it will result in a compilation error.
Can a class be defined inside an Interface ?
Yes.
Is an interface be defined inside a class ?
Yes.
What kind of variables a class can consists of ?
A class consists of following variables:
1. Local variable
2. Instance variable
3. Class variable
Which Java operator is right associative ?
The = operator is right associative.
Is a dead thread be restarted ?
No, a dead thread cannot be restarted.
Is a class declared as private be accessed outside it’s package ?
No.
Is it possible to override the main method ?
No.
Can we instantiate an abstract class ?
No, Its only purpose is to be extended.
Can constructor be inherited ?
No, constructor cannot be inherited but a derived class can call the base class constructor.
Is null a keyword ?
No.
What modifiers can be used with a top-level class ?
A top-level class used a public, abstract, or final modifiers.
What is the argument of main() method ?
It accepts an array of String object as an argument.
Is the order of public and static declaration matter in main() method ?
No. It doesn’t matter but void should always come before main().
Which package is imported by default ?
java.lang package is imported by default.
Is try statement be nested ?
Yes.
What is a package ?
A package is a collection of related classes and interfaces. A package declaration should be the first statement in a java.
What is the default value for an instance variable in java ?
All instance variables are initialized to “null” by default in java.
Are true and false keywords ?
No.
Name the types of memory areas allocated by JVM ?
JVM allocated memory areas in many forms:
1. Class(Method) Area
2. Heap
3. Stack
4. Program Counter Register
5. Native Method Stack
Name the return type of a program’s main() method ?
void.