Test Java Online

1. Qual è l’istruzione di controllo che permette di scegliere tra due alternative?
A. for
B. if
C. while

Question 1 of 10

2. Quale sarà l'output
for(int i = 0; i < 3; i++) 
{ 
    switch(i) 
    { 
        case 0: break; 
        case 1: System.out.print("one "); 
        case 2: System.out.print("two "); 
        case 3: System.out.print("three "); 
    } 
} 
System.out.println("done")

Question 2 of 10

3. Qual è l’output del seguente codice:
public class TestDue {

    int prova = 0;

    public void aggiungi(int prova) {
        this.prova = prova + 10;
    }

    public static void main(String[] args) {
        int prova = 0;
        TestDue oggetto = new TestDue();
        oggetto.aggiungi(100);
        System.out.println(prova);
    }
}
 

Question 3 of 10

4. Qual è il valore di a dopo aver eseguito l’istruzione a--, se a, all’inizio, vale 7?
A. true
B. 7
C. 6

Question 4 of 10

5. Qual è il risultato della seguente espressione: “1” + “3”?
A. “4”
B. “6”
C. “13”

Question 5 of 10

6. Quale sarà l'output del seguente codice.
class Base {
    public void show() {
       System.out.println("Base::show() called");
    }
}
  
class Derived extends Base {
    public void show() {
       System.out.println("Derived::show() called");
    }
}
  
public class Main {
    public static void main(String[] args) {
        Base b = new Derived();;
        b.show();
    }
}
 

 

Question 6 of 10

7. Qual'è l'output del seguente codice:

 
public class Main {
    public static void main(String args[]) {
       int arr[] = {10, 20, 30, 40, 50};
       for(int i=0; i < arr.length; i++)
       {
             System.out.print(" " + arr[i]);              
       }
    }
}
 

Question 7 of 10

8. Quale sarà l'output del seguente codice:
class Test
{
    String str = "a";
 
    void A()
    {
        try
        {
            str +="b";
            B();
        }
        catch (Exception e)
        {
            str += "c";
        }
    }
 
    void B() throws Exception
    {
        try
        {
            str += "d";
            C();
        }
        catch(Exception e)
        {
            throw new Exception();
        }
        finally
        {
            str += "e";
        }
 
        str += "f";
 
    }
     
    void C() throws Exception
    {
        throw new Exception();
    }
 
    void display()
    {
        System.out.println(str);
    }
 
    public static void main(String[] args)
    {
        Test object = new Test();
        object.A();
        object.display();
    }
 
}
 

Question 8 of 10

9. Quale sarà l'output del seguente codice.
class Base {
    final public void show() {
       System.out.println("Base::show() called");
    }
}
  
class Derived extends Base {
    public void show() {
       System.out.println("Derived::show() called");
    }
}
  
class Main {
    public static void main(String[] args) {
        Base b = new Derived();;
        b.show();
    }
}
 

 

Question 9 of 10

10. Quale sarà l'output del programma:
public class ThreadDemo 
{ 
    private int count = 1; 
    public synchronized void doSomething() 
    { 
        for (int i = 0; i < 10; i++) 
            System.out.println(count++); 
    } 
    public static void main(String[] args) 
    { 
        ThreadDemo demo = new ThreadDemo(); 
        Thread a1 = new A(demo); 
        Thread a2 = new A(demo); 
        a1.start(); 
        a2.start(); 
    } 
} 
class A extends Thread 
{ 
    ThreadDemo demo; 
    public A(ThreadDemo td) 
    { 
        demo = td; 
    } 
    public void run() 
    { 
        demo.doSomething(); 
    } 
}

Question 10 of 10


 

7 risposte a “Test Java Online”

    1. purtroppo le domande sono random e quindi non riesco a verificare se il punto 7 è errato. In ogni caso, grazie per la segnalazione

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *