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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick

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

Post by The_Nick »

Hi,
I thought that it was line 4 as even though the "x" and "y" variables are not initialized (hence the code will not compile), as a constructor should be consider valid. No?
It cannot start with a tilde? I don't see why it's not a valid constructor besides the fact that does not compile.

Thanks in advance.

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

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

Post by admin »

You can't start a method or constructor with ~. It will not compile because of that as well.

The_Nick

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

Post by The_Nick »

So making a recap, to be a correct identifier it must be of a range of letter [A-Z] [a-z] digits [0-9]. It must not begin with a digit. $ and _ are also valid character.
That's what I found on line. But I also noticed that an identifier as int £34$_ =10; works well.

Does it mean that any currency symbol can be used in an identifier?

Thanks in advance.


The_Nick

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

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

Post by admin »


swziy123
Posts: 1
Joined: Sat Apr 05, 2014 10:54 am
Contact:

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

Post by swziy123 »

Question is "Which line contains a valid constructor in the following class definition?"

and line:
public TestClass getInstance() { return new TestClass(); }

CONTAINS valid constructor, because new TestClass() is a valid default constructor. Question sentence is misleading.

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

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

Post by admin »

The sentence is correct. new TestClass(); is not a constructor, it is an invocation of a constructor.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests