About Question enthuware.ocajp.i.v7.2.1012 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
bhavinjparmar
Posts: 1
Joined: Sun Jun 24, 2012 4:49 am
Contact:

About Question enthuware.ocajp.i.v7.2.1012 :

Post by bhavinjparmar »

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.

Online
admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1012 :

Post by admin »

Constructor do not have (;) at the end.
There is no such rule. Extra semi colon is not an issue. So option 5 is also correct.

HTH,
Paul.

nikitos
Posts: 21
Joined: Mon Oct 24, 2016 6:55 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1012 :

Post by nikitos »

Hi!
As I understand - in explanation:
"Constructor can be public, private or protected, but can not be abstract, static or synchronized."
missed package private access type for constructor

Online
admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1012 :

Post by admin »

You have misquoted the explanation. It actually says:
You can apply public, private, protected to a constructor. But not static, final, synchronized, native and abstract.
So yes, it can be without any access modifier also, which means package private :)
I have updated the explanation to make it clear. Thank you for your feedback!
HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 10 guests