6 years ago in Java Strings

What will happen when you compile and run the following code?
public class MyClass{

static int i;

public static void main(String argv[]){




[A] Error Variable i may not have been initialized
[B] null
[C] 1
[D] 0
Next Question

Create your Digital Resume For FREE on your name's sub domain "yourname.wcard.io". Register Here!

Overall Stats

Attempted 336
Correct 73
Incorrect 134
Viewed 129


Swapnali Kumbhar - 3 years ago

it prints 0

Dipak Raut - 4 years ago

it gives 0 as output , as global var no need to initialise , default value is 0

Mircea Cristea - 6 years ago

It prints 0.

keziah - 3 months ago

keziah from Colombo, Sri Lanka is saying null is correct answer

Youssef Aserrar
Youssef Aserrar - 7 months ago

Youssef Aserrar from Casablanca, Morocco is saying 0 is correct answer

Related Questions

What will happen if you try to compile and run the following code ?
public class MyClass {

    public static void main(String arguments[]) { 


    public void amethod(String[] arguments) { 



  • [A] error Can't make static reference to void method.
  • [B] error method main not correct
  • [C] error array must include parameter
  • [D] amethod must be declared with String

What is the difference between a TextArea and a TextField?

  • [A] A TextArea can handle multiple lines of text
  • [B] A textarea can be used for output
  • [C] TextArea is not a class
  • [D] TextAreas are used for displaying graphics

What is the output of the code ?
public class AQuestion{

      private int i = j;

      private int j = 10;

      public static void main(String args[]){

            System.out.println((new AQuestion()).i);



  • [A] Compiler error complaining about access restriction of private variables of AQuestion.
  • [B] Compiler error complaining about forward referencing.
  • [C] No error - The output is 0;
  • [D] No error - The output is 10;