Page 1 of 1

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

Posted: Thu Jan 07, 2021 11:04 am
by Denyo1986

Code: Select all

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
}
Does the semicolon in line 5 not make this option a wrong option?

Line 1 and 4 are clear. 2 is a method, 3 has no body.
Wouldnt line 5 be wrong?

Have never seen this before...


Maybe the idea is that we see a constructor and an empty statement, is that the case?

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

Posted: Thu Jan 07, 2021 12:11 pm
by admin
Having a semicolon after the closing } at end of the method is not wrong. It is redundant but not wrong.
You can try it out.

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

Posted: Thu Jan 07, 2021 12:22 pm
by Denyo1986
Yeah I did with big surprise :)
Tricky questions....good though :)