• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

output of the following code..

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What will happen if you attempt to compile and run the following code?

class Base{}
class CatMat{
int i = 99;
int j= 100;
public static void main(String argv[]){
new CatMat(new Base());

}
public void alex( final int i){
System.out.println(i+j);

}
CatMat( Object o){
alex(1);
}
}

the output according to me will be 101 but it gives me a runtime exception..
pls help
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ashutosh mondal:
What will happen if you attempt to compile and run the following code?

class Base{}
class CatMat{
int i = 99;
int j= 100;
public static void main(String argv[]){
new CatMat(new Base());

}
public void alex( final int i){
System.out.println(i+j);

}
CatMat( Object o){
alex(1);
}
}

the output according to me will be 101 but it gives me a runtime exception..
pls help





Hi Ashutosh,
Its working fine.Hope somewhere you went wrong.

-Thanks & Regards,
Hamsa
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Ashutosh.

The output is indeed 101. Try saving the file as "CatMat.java", then run it with java CatMat - it should work
[ March 14, 2008: Message edited by: Roberto Perillo ]
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dude, runs fine for me
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic