Page 1 of 1

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

Posted: Sun Nov 16, 2014 11:34 am
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?

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

Posted: Mon Nov 17, 2014 3:43 am
by admin
You are right. Fixed.
thank you for your feedback!

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

Posted: Mon Feb 23, 2015 7:25 pm
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

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

Posted: Mon Feb 23, 2015 7:27 pm
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