Test Java Online

1. Le interfacce devono essere estese o implementate?

Question 1 of 10

2. Considerare il seguenti due cicli:
for (int i=0; i<10; i++)       // CICLO 1
    System.out.println(10-i);

int i=10;
while(i>1) {                   // CICLO 2
    System.out.println(i);
    i--;
}
Una sola delle seguenti affermazioni è vera. Quale?

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. Considerando il seguente frammento di codice:
class ThreadDemo extends Thread {
  final StringBuffer sb1 = new StringBuffer();
  final StringBuffer sb2 = new StringBuffer();

  public static void main(String args[]) {
    final ThreadDemo h = new ThreadDemo();
    
    
    
    new Thread() {
      public void run() {
        synchronized (this) {
          h.sb1.append("Java");
          h.sb2.append("Thread");
          System.out.println(h.sb1);
          System.out.println(h.sb2);
        }
      }
    }.start();
    
    
    
    new Thread() {
      public void run() {
        synchronized (this) {
          h.sb1.append("Multithreading");
          h.sb2.append("Example");
          System.out.println(h.sb2);
          System.out.println(h.sb1);
        }
      }
    }.start();
  }
}
 

Quale output verrà prodotto:

 

 

 

Question 4 of 10

5. Quale sarà l'output
interface calculate {
            int VAR = 0;
            void cal(int item);
        }
        class display implements calculate {
            int x;
          public  void cal(int item) {
                if (item<2)
                    x = VAR;
                else
                    x = item * item;            
            }
        }
 class interfaces {
 
            public static void main(String args[]) {
                display[] arr=new display[3];
 
               for(int i=0;i<3;i++)
               arr[i]=new display();
               arr[0].cal(0);    
               arr[1].cal(1);
               arr[2].cal(2);
               System.out.print(arr[0].x+" " + arr[1].x + " " + arr[2].x);
            }
        }

Question 5 of 10

6. 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 6 of 10

7. La keyword final applicato ad un metodo permette di

Question 7 of 10

8. Cos'è l'overloading di un metodo?

Question 8 of 10

9. Quale delle seguenti espressioni, se a è uguale a 7, fornisce un valore true come risultato?
A. a < 7;
B. a == 7;
C. a > 7

Question 9 of 10

10. Quale dei codici seguenti genera un ciclo infinito?
A. While(false){}
B. While(true){}
C. While(5==9){}

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 *