fork download
  1. class tem{
  2. int a=10;
  3. int b=30;
  4. public static void main(String args[]){
  5. int temp=a;
  6. a=b;
  7. b=temp;
  8. System.out.println("the swapped no"+a);
  9. System.out.println("the swapped no"+b);
  10. }
  11. }
  12.  
  13.  
  14.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: non-static variable a cannot be referenced from a static context
int temp=a;
         ^
Main.java:6: error: non-static variable a cannot be referenced from a static context
a=b;
^
Main.java:6: error: non-static variable b cannot be referenced from a static context
a=b;
  ^
Main.java:7: error: non-static variable b cannot be referenced from a static context
b=temp;
^
Main.java:8: error: non-static variable a cannot be referenced from a static context
System.out.println("the swapped no"+a);
                                    ^
Main.java:9: error: non-static variable b cannot be referenced from a static context
System.out.println("the swapped no"+b);
                                    ^
6 errors
stdout
Standard output is empty