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

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
BenjaminGray
Posts: 2
Joined: Sun Nov 16, 2014 11:25 am
Contact:

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

Post by BenjaminGray »

The question is
What is the correct declaration for an abstract method 'add' in a class that is accessible to any class, takes no arguments and returns nothing?
And the explanation for the third option, which is
abstract null add();
is
A method that is not supposed to return anything must specify void as its return type. null is not a  type, though it is a valid return value for any type.
I think null is only a valid return value for any reference type. You can't return null as a primitive value. If you try to do this:

Code: Select all

int m1{return null;}
The compiler will complain:
Type mismatch: cannot convert from null to int
Did I miss something?

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

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

Post by admin »

You are right. Fixed.
thank you for your feedback!

mutley
Posts: 6
Joined: Mon Feb 23, 2015 9:37 am
Contact:

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

Post by mutley »

your question: what is the correct declaration for an abstract method 'add' in a class that is accessible to any class, takes no arguments and returns nothing?

the first option "public void add();" (in my bank of question at least) ...I guess is correct in the methos would be declared in an Interface isn't it?

public Interface myinterface
{
public void add();
}
this method would be by default public and abstract ... so in this case your question would have 2 correct answers

mutley
Posts: 6
Joined: Mon Feb 23, 2015 9:37 am
Contact:

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

Post by mutley »

mutley wrote:your question: what is the correct declaration for an abstract method 'add' in a class that is accessible to any class, takes no arguments and returns nothing?

the first option "public void add();" (in my bank of question at least) ...I guess is correct in the methos would be declared in an Interface isn't it?

public Interface myinterface
{
public void add();
}
this method would be by default public and abstract ... so in this case your question would have 2 correct answers
Sorry , rading better the question , "in a class" poped up ...so no interface there .

mea culpa

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests