1.What is the output of the following code?
public class TestEquals{
public static void main(String[] args){
String str1 = "test";
String str2 = new String("test");
String str3 = "test";
System.out.println(str1 == str2);
System.out.println(str1 == str3);
System.out.println(str1.equals(str2));
System.out.println(str1.equals(str3));
}
}
2.Equals hash codes imply that the objects are equals.True or False?
3.What is the size of the character data type in bytes?
4.Check the following code
class A {
public void doSomething(){}
}
class B extends A {
private void doSomething(){}
}
a.Is it an example of method overloading OR method overriding?
b.Will the program throw compilation error,runtime error OR compile and run without any errors?
5.Check the following code
class C {
private void doSomething(){}
}
public class D extends C {
public void doSomething(){}
}
a.Is it an example of method overloading OR method overriding?
b.Will the program throw compilation error,runtime error OR compile and run without any errors?
6.Let us assume you only have a single user-defind public java class,the java compiler and java interpreter with you.It does not have a public static void main() method.Is it possible to execute any random code of your choice in such a java class?
For this question,you are NOT supposed to use any other API class or user-defined class.if you think it is possible,please write the code of the single class.if you think otherwise,please explain why it is not possible to execute code in such a class.
7.Can an abstract class have a "public static void main(String[] args)" method?
8.Check the following code
interface SuperInterface {
void walk();
}
interface SubInterface implements SuperInterface {
void run();
}
public class TsetInterface implements SubInterface {
@Override
public void walk(){
System.out.println("I am walking");
}
@Override
public void run(){
System.out.println("I am running");
}
public static void main(String[] args) {
TestInterface ti = new TestInterface();
ti.walk();
ti.run();
}
}
Which of the following is correct?
a Code throws compilation error
b Code throws run-time error
c Code runs fine and output is:
I am walking
I am running
9.When calling the main() method of a java class,if we do not provide any arguments on the command line,then the string array of main() method-will it be empty or null?
10.When differentiating overloaded methods does the compiler consider the return type of the method?
11.Can we override an overloaded method?
12.Can you overload the "public static void main(String[] args)" method in java?
13.Can you override a static or final method in java?
14.Can you declare a constructor as final in java?
15.Is java pass-by-value Or pass-by-reference?
16.Can an interface implement another classes?
17.Which object oriented concept is achieved by using overloading and overriding?
18.Which class is extended by all other classes?
19.Can a transient variable be serialized?
20.Is the String class declared final?
21.When does the garbage collector call the finalize() method?
22.Write the signature of the finalize() method?
23.Object E has reference to object F and object F has reference to object E.There are no other references to objects E and F.Select the correct answer.
a. No objects will be garbage collected as E has reference to F and F has reference to E.
b. Only object E will be garbage collected
c. Only object F will be garbage collected
d. Both objects E and F will be garbage collected
24.Can we call the garbage collector from java code?if yes,how?if no,why not?
25.Can we force garbage collector to run?
26.How can you monitor garbage collection?
27.Can you change values of an immutable object?
28.List the different access specifiers