my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Method which isn't a constructor should have a return type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Method which isn Watch "Method which isn New topic
Author

Method which isn't a constructor should have a return type

Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
com.enthuware.ets.scjp.v5.2.550



Enthuware is stating that this code would not compile because a top level class shouldn't be private.

I would say this code would not compile because TC in class TestClass is no constructor and should have a return type.
[ June 12, 2007: Message edited by: Remko Strating ]

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Alex Burda
Greenhorn

Joined: Jun 08, 2007
Posts: 2
Looks like you're correct:
TestClass.java:12: invalid method declaration; return type required
public TC()
^
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Remko Strating:
...Enthuware is stating that this code would not compile because a top level class shouldn't be private.

I would say this code would not compile because TC in class TestClass is no constructor and should have a return type...

I would say both are true, and easily verified.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Louis Moloney
Ranch Hand

Joined: Feb 06, 2007
Posts: 59
you are right it doesn' t compile because of the incorrect method/constructor.

when you correct that it wont compile because a top level class cannot be private (can only be public or default).

i know this because i ran it, like Marc say this is easily verified by trying it out.
[ June 12, 2007: Message edited by: Louis Moloney ]

saurabhs mittals
Greenhorn

Joined: Mar 05, 2007
Posts: 4
saurabh mittal
saurabhs mittals
Greenhorn

Joined: Mar 05, 2007
Posts: 4
hi sir,
enthuware is true according to concept of method overriding but he is wrong bcoz method overriding is not apply on constructors.Reason is that constructor have no return type so we cant say constructor like a method and entuware wrongly used constructor as normal method.
any class can have default or public access modifier so private cant use here.
sundar sankar
Ranch Hand

Joined: May 30, 2007
Posts: 42
Hi,
constructor are not inherited by the child class,hence overridding does't come in picture.
bye
sankar
Akbar Khan
Greenhorn

Joined: Jun 13, 2007
Posts: 24
If at first the top class itself is private < wrong thing>..why will the compiler go and check other details inside theclass & methods ?

So what Enthuware is right.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method which isn't a constructor should have a return type