Thursday, September 24, 2009

JAVA Certification SCJP : operators

Here is an SCJP certification exercise about operators.

Exercice :

class Arg {

public static void main(String[] args){
int i = 6;

if ( i && 12 ){

System.out.println("OK!");

} else {

System.out.println("KO!");

}

}

}

What is the result ?

A : OK!

B : KO!

C : compilation fails

D : An exception is thrown at runtime





Soultion :

The compilation will fail because of i && 12.The && and || work with boolean operators only !