Submitted by c-admin on Thu, 05/30/2019 - 03:40
What will the following program print when compiled and run?
class Data {
private int x = 0;
private String y = "Y";
public Data(int k){
this.x = k;
}
public Data(String k){
this.y = k;
}
public void showMe(){
System.out.println(x+y);
}
}public class TestClass {
public static void main(String[] args) throws Exception {
new Data(10).showMe();
new Data("Z").showMe();
}
}
Select 1 option
A. 0Z
10Y
B. 10Y
0Z
C. It will not compile.
D. It will throws an exception at run time.
Submitted by c-admin on Thu, 05/30/2019 - 03:25
Consider the classes shown below:
class A{
public A() { }
public A(int i) { System.out.println(i ); }
}
class B{
static A s1 = new A(1);
A a = new A(2);
public static void main(String[] args){
B b = new B();
A a = new A(3);
}
static A s2 = new A(4);
}
Which is the correct sequence of the digits that will be printed when B is run?
Select 1 option
A. 1 ,2 ,3 4.
B. 1 ,4, 2 ,3
C. 3, 1, 2, 4
D. 2, 1, 4, 3
E. 2, 3, 1, 4
Submitted by c-admin on Thu, 05/30/2019 - 03:23
Which of the following classes have a default constructor?
class A{ }
class B { B(){ } }
class C{ C(String s){ } }
Select 1 option
A. A
B. A and B
C. B
D. C
E. B and C
Submitted by c-admin on Thu, 05/30/2019 - 03:19
Which of the following can be used as a constructor for the class given below?
public class TestClass{
// lots of code ...
}
Select 2 options
A. public void TestClass() {...}
B. public TestClass() {...}
C. public static TestClass() {...}
D. public final TestClass() {...}
E. public TestClass(int x) { ...}
Submitted by c-admin on Thu, 05/30/2019 - 03:13
Which lines contain a valid constructor in the following code?
public class TestClass{
public TestClass(int a, int b) { } // 1
public void TestClass(int a) { } // 2
public TestClass(String s); // 3
private TestClass(String s, int a) { } //4
public TestClass(String s1, String s2) { }; //5
}
Select 3 options
A. Line // 1
B. Line // 2
C. Line // 3
D. Line // 4
E. Line // 5
Pages