Hard code

3 respostas
S

Hi folks,

I will take the opportunity to leave some questions that for sure will make your heads crazy, let’s go !!

here is the first one:

what happens with this code ?

class TestClass

{

int i;

public TestClass(int i) { this.i = i;  }

public String toString()

{

if(i == 0) return null;

else return “”+i;

}

public static void main(String[ ] args)

{

TestClass t1 = new TestClass(0);

TestClass t2 = new TestClass(2);

System.out.println(t2);

System.out.println(""+t1);

}

}

3 Respostas

urubatan

se não to enganado
2
null

ou então
2
<linah em branco>

só se eu testar qui para ter certeza :slight_smile:

cv1

Vai imprimir isso:

2 null

Mas, afinal, qual o problema com esse codigo?

S

what numbers will be printed by this sample?

look twice, before answer, there is a trap below :frowning:

public class ForSwitch

{

public static void main(String args[])

{

char i;

LOOP:   for (i=0;i<5;i++)

{

switch(i++)

{

case 0: System.out.println(A);

case 1: System.out.println(B); break LOOP;

case 2: System.out.println(C); break;

case 3: System.out.println(D); break;

case 4: System.out.println(E);

case E : System.out.println(F);

}

}
}

}

Criado 17 de maio de 2003
Ultima resposta 17 de mai. de 2003
Respostas 3
Participantes 3