What will be the output of the following code segment? - ProProfs Discuss
Advertisement

What will be the output of the following code segment?

class Number{int a;public static void main(String ar[]){ a=10;int b=20;a=a+b;b=a-b;a=a-b;System.out.println(a = +a);System.out.println(b = +b);}}

Asked by Wyatt Williams, Last updated: Feb 20, 2024

+ Answer
Request
Question menu
Vote up Vote down

1 Answer

John Smith

John Smith

John Smith
John Smith

Answered Jan 23, 2017

Compile-time error

Non-static variable cannot be referenced from a static context. a is a non-static variable, it cannot be referenced from within main() which is static.
upvote downvote
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

Email Sent
We have sent an email to your address "" with instructions to reset your password.