What will be the output of the following code segment?class - 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 Maverick_virgo, Last updated: Aug 20, 2023

+ Answer
Request
Question menu
Vote up Vote down

1 Answer

maverick_virgo

maverick_virgo

maverick_virgo
Maverick_virgo

Answered Dec 06, 2018

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.