File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes help me in static keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help me in static keyword" Watch "help me in static keyword" New topic

help me in static keyword

premanand sreedharan

Joined: May 06, 2007
Posts: 5
class test
static int i=10;
public static void main(String a[])
test t=new test();
System.out.println(" ans1"+i+"ans2"+t.i);

why does these two output differ? i got two different answers for this pls help me in this
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
What is different?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Keith Lynn:
What is different?

Maybe he means he gets 110 and 210?

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1710

Maybe he means he gets 110 and 210?

Wow Barry!

Premanand's wariness forced me to go and see the output and really at first I was surprised seeing output.


I agree. Here's the link:
subject: help me in static keyword
It's not a secret anymore!