-
} ">
The following code defines the ThreadSample class. public class ThreadSample implements Runnable { public static void main(String args[]) { System.out.println("This is the ThreadSample object"); }
/ The following code defines the ThreadSample class. public class ThreadSample implements Runnable { public static void main(String args[]) { System.out.println("This is the ThreadSample object"); } public void run() { while (true) { try { Thread.sleep(100); System.out.println("Thread ran."); } catch (Exception e) {} } Referring to the sample...
-
What is the purpose of garbage collection
The purpose of garbage collection is to identify and discard objects that are no longerneeded by a program so that their resources may be reclaimed and reused.
-
What is the difference between static and non-static variables
A static variable is associated with the class as a whole rather than with specific instancesof a class. Non-static variables take on unique values with each object instance.
-
Java Program Execution
How does Java program compile and execute to give output?
-
-
What is the difference between exception and error
Answered by Scott on 2005-05-12 09:50:36: An Exception can be caught and recovered: ArrayIndexOutOfBoundsException means you tried to access a position of an Array that does not exist - no big deal. An Error is unrecoverable: OutOfMemoryError means that the JVM has no more memory to contin
-
Which of the following statements correctly describes the relation between an object and the instance variable it stores? (Select multiple)
A) Each new object has its own distinctive set of instance variablesB) Each object has a copy of the instance variables of its classC) the instance variable of each object are seperate from the variables of other objectsD) The instance variables of each object are stored together with the variables of other objects
-
-
Which of the following methods are methods of the Math class?
A) absolute( )B) log( )C) cosine( )D) sine( )
-
What are the legal operands of the instanceof operator
The left operand is an object reference or null value and the right operand is a class,interface, or array type.
-
What is the output of below syntax?
java{
cath(Exception e)
{System.out.println("A");
}
cath(ClassNotFoundException e1)
{System.out.println("b");
}
cath(InvalidException e2)
{System.out.println("c");
}
finally()
{
System.out.println("x");
}
-
Thread and Runnable
When we will use thread and runnable in java program ?
-
Which of the following options can be inserted at the commented line to compile the given code:
cpublic class Class1 {
Class1(String s){ }
Class1() { }
}
class Class2 extends Class1{
Class2(){ }
Class2(String s) {super(s);}
void m1() {
// insert code here
}
}
a) Class1 c1 = new Class1("HCL"){ }
b) Class1 c1 = new Class2(){ };
c) Class2 c3 = new Class1(String s){};
d) Class1 c1 = new Class1(100){ }; -
Select appropriate answers for the incomplete declaration listed below?
class A ______ B ______ C { } // line 4
a) The 1st blank should be extends and the 2nd blank should be implements.
b) The 1st blank should be implements and the 2nd blank should be extends.
c) B is a class and C is an interface
d) B and C can be either class or interface depending upon the placement of extends or implements in the 1st or 2nd blank. -
When to use Interface over abstract class?
Abstract Classes: Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying ClassAbs abs = new ClassAbs(); where ClassAbs is abstract class.Abstarct classes contains have one or more abstarct methods, ie method body only no implementation.Interfaces: These are same as abstract classes only difference is we an only define...
-
-
-
-
Swing provides ________ text components
Skill/Topic: AWT & AppletsA) fourB) SixC) Sixteen D) Thirtytwo
-
Call Main Function Explicitly
Can we call the main function explicitly? If Yes, How?
Java Interview Questions
Ans