Submitted by heartin on Sun, 09/27/2015 - 18:19
Find output:
public class MyClass {
int id;
public static void main(String[] args) throws Exception {
MyClass mc = new MyClass();
mc.id=10;
System.out.println(((MyClass)mc.clone()).id);
}
}
Submitted by heartin on Sun, 09/27/2015 - 18:16
Find output:
public class MyClass {
int id;
public static void main(String[] args) throws Exception {
MyClass mc = new MyClass();
mc.id=10;
System.out.println(mc.clone().id);
}
}
Submitted by heartin on Mon, 09/14/2015 - 10:57
Find output or error:
public class NullCheck {
public void myMethod(String str) {
System.out.println("String");
}
public void myMethod(Double d) {
System.out.println("Double");
}
public static void main(String[] args) {
NullCheck nc = new NullCheck();
nc.myMethod(null);
}
}
Submitted by heartin on Mon, 09/14/2015 - 10:51
Find output or error:
class OOP2 {
int x(double d) {
System.out.println("one");
return 0;
}
String x(double d) {
System.out.println("two");
return null;
}
double x(double d) {
System.out.println("three");
return 0.0;
}
public static void main(String[] args) {
new OOP2().x(4.0)
}
}
Submitted by heartin on Mon, 09/14/2015 - 10:49
Given:
public class X implements Z {
public String toString() {
return "I am X";
}
public static void main(String[] args) {
Y myY = new Y();
X myX = myY;
Z myZ = myX;
System.out.println(myZ);
}
}
class Y extends X {
public String toString() {
return "I am Y";
}
}
interface Z {}
What is the reference type of myZ and what is the type of the object it references?
Pages