• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like you're correct:
TestClass.java:12: invalid method declaration; return type required
public TC()
^
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
saurabh mittal
 
saurabhs mittals
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
constructor are not inherited by the child class,hence overridding does't come in picture.
bye
sankar
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic