Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem while compiling

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code compiles fine.
class ThisTest {
final int ijjj;
ThisTest(){
this( 5 ); }
ThisTest( int x ){
this();
System.out.println( "this( int )" );
}
public static void main(String[] args) {
ThisTest tt = new ThisTest();
}
}
But when i remove the 2 constructors it is giving the following error:
variable ijjj might not have been initialized
class ThisTest {
^
I have n't understood
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A blank final field like ijjj needs to have a value assigned by one of these means:
1. In every constructor.
2. In an instance initializer.
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I tries it, I got one error mesg !
--------------------------------------------------
ThisTest.java:8: recursive constructor invocation
ThisTest( int x ){
^
1 error
--------------------------------------------------

Originally posted by shiva thadakamadla:
The following code compiles fine.

 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Shiva -
I'm surprised you're not overflowing your stack, because your two constructors are calling each other. (One should call super(), but you can't have a call to super() and a call to this() in the same constructor.) Some compilers will permit this -- though it won't run properly -- while others will generate a compile error.
Also, your constructor needs to initialize the final variable ijjj or your code won't compile.
Regards,
Jeff
[ August 25, 2003: Message edited by: Jeff Bosch ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A final variable has to be initialized either at the class level or in the constructor.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic