About Question enthuware.ocajp.i.v7.2.1012 :
Posted: Thu Jun 28, 2012 9:02 am
Question in Test Studio:
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
}
I believe: (Is there anything wrong in my understanding)
- Constructor can accept arguments, but no return types.
- Constructor can be public, private or protected, but can not be abstract, static or synchronized.
- Constructor's do have same name in same case as class name.
- Constructor do not have (;) at the end.
If it is true then only 1 and 4 are true constructor, cause option 5 is having semicolone at the end like option 3 while option 2 have return type.
So there are actually only 2 correct options and question asks to provide 3 correct answers.
Kindly requested to provide guideline on the aboe question.
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
}
I believe: (Is there anything wrong in my understanding)
- Constructor can accept arguments, but no return types.
- Constructor can be public, private or protected, but can not be abstract, static or synchronized.
- Constructor's do have same name in same case as class name.
- Constructor do not have (;) at the end.
If it is true then only 1 and 4 are true constructor, cause option 5 is having semicolone at the end like option 3 while option 2 have return type.
So there are actually only 2 correct options and question asks to provide 3 correct answers.
Kindly requested to provide guideline on the aboe question.