Page 1 of 1
About Question enthuware.oce-jpad.v6.2.546 :
Posted: Wed Oct 10, 2012 7:59 am
by sacintha
How can an abstract class have a No-arg constructor
Re: About Question enthuware.oce-jpad.v6.2.546 :
Posted: Sun Oct 14, 2012 10:05 am
by admin
An abstract class can certainly have a no-args constructor.
-Paul.
Re: About Question enthuware.oce-jpad.v6.2.546 :
Posted: Mon Sep 16, 2013 3:14 pm
by unknownartist
"Identify the correct statements about following code"
Answer is "It must have no-args constructor."
But I think answer must be "It is a valid @Entity class."
Because no-args constructor will be created by compiler.
Re: About Question enthuware.oce-jpad.v6.2.546 :
Posted: Mon Sep 16, 2013 4:13 pm
by admin
unknownartist wrote:"Identify the correct statements about following code"
Answer is "It must have no-args constructor."
But I think answer must be "It is a valid @Entity class."
Because no-args constructor will be created by compiler.
In the given class code, an explicit constructor is already present:
Code: Select all
public Vehicle(String code){ mfgCode = code; }
So the compiler will not create the no-args constructor. That is why it is not a valid Entity class.
HTH,
Paul.
Re: About Question enthuware.oce-jpad.v6.2.546 :
Posted: Sat Mar 14, 2015 9:11 am
by ikotev
By the way entity has public field:
public String mfgCode;
and as per section "2.2 Persistent Fields and Properties" of the specification:
The instance variables of a class must be private, protected, or package visibility independent of whether field access or property access is used.
does anyone know why RI EclipseLink accepts public fields in entities and doesn't throw exceptions ?
Re: About Question enthuware.oce-jpad.v6.2.546 :
Posted: Sat Mar 14, 2015 11:21 am
by admin
Yes, this is another reason why the entity is invalid.
Regarding why EclipseLink accepts public fields, I think that is just an oversight. There are several instances where RI or other persistence providers does not follow the specification to the dot. I think we have noted such cases in some of our questions as well.
HTH,
Paul.