About Question enthuware.oce-jpad.v6.2.546 :

Moderator: admin

Post Reply
sacintha
Posts: 1
Joined: Wed Oct 10, 2012 7:58 am
Contact:

About Question enthuware.oce-jpad.v6.2.546 :

Post by sacintha »

How can an abstract class have a No-arg constructor

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

Re: About Question enthuware.oce-jpad.v6.2.546 :

Post by admin »

An abstract class can certainly have a no-args constructor.
-Paul.
Last edited by admin on Mon Sep 16, 2013 4:33 pm, edited 1 time in total.
Reason: cleaned up uninformational text
If you like our products and services, please help us by posting your review here.

unknownartist
Posts: 5
Joined: Sat Aug 31, 2013 5:39 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.546 :

Post 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.

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

Re: About Question enthuware.oce-jpad.v6.2.546 :

Post 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.
If you like our products and services, please help us by posting your review here.

ikotev
Posts: 17
Joined: Sat Feb 28, 2015 2:26 am
Contact:

Re: About Question enthuware.oce-jpad.v6.2.546 :

Post 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 ?

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

Re: About Question enthuware.oce-jpad.v6.2.546 :

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests