This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Remko Strating
Ranch Hand
Posts: 893
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Alex Burda
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you're correct:
TestClass.java:12: invalid method declaration; return type required
public TC()
^
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Louis Moloney
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saurabh mittal
 
saurabhs mittals
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
constructor are not inherited by the child class,hence overridding does't come in picture.
bye
sankar
 
Akbar Khan
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic