• 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

constructor

 
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Just
{
int a = 10 ;
Just ( )
{
call ( ) ;
}
void call ( )
{
System . out . print( "a = " + a + " ") ;
}
}
class Q05 extends Just
{
int b = 16 ;
Q05 ( )
{
call ( ) ;
}
void call ( )
{
System.out.print( " b = " + b + " " ) ;
}
public static void main ( String args [ ] )
{
new Q05 ( ) ;
}
}

when i run this code i got the output as
---------- Java ----------
java.lang.NoSuchMethodError: main
Exception in thread "main" Normal Termination
Output completed (0 sec consumed).
-------------------------------------------
So what is the problem and also what i need to do avoid such problems.
 
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is valid code output is 0 and 16
Just() { call(); } also calls call() of Q05 or subclass as
object constructed is of Q05 but b is not initialized so
0 than in Q05 constrcutor call() prints 16.
 
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
Are you trying to run Just (which does not have a main method), or are you trying to run Q05 (which does have a main method)?
[ September 20, 2005: Message edited by: marc weber ]
 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ho i made mistake by running :just"

I didnot understand how the first value printed is 0.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic