Test Java Online

1. Quale sarà l'output del seguente codice:
class Test
{
    public static void main(String[] args)
    {
        try
        {
            int a[]= {1, 2, 3, 4};
            for (int i = 1; i <= 4; i++)
            {
                System.out.println ("a[" + i + "]=" + a[i] + "n");
            }
        }
         
        catch (Exception e)
        {
            System.out.println ("error = " + e);
        }
         
        catch (ArrayIndexOutOfBoundsException e)
        {
            System.out.println ("ArrayIndexOutOfBoundsException");
        }
    }
}
 

Question 1 of 10

2. Quali valori di “i” stamperà il seguente codice: for (int i = 0; i < 10; i++) { System.out.println(i); }
A. Non stampa nulla
B. Stampa i numeri da 0 a 9
C. Stampa i numeri da 0 a 10

Question 2 of 10

3. Data la classe cerchio, quale delle seguenti descrizioni la rappresenta correttamente, in quanto classe e non in quanto oggetto?

Question 3 of 10

4. Quale sarà l'output del seguente codice.
final class Complex {
 
    private final double re;
    private final double im;
 
    public Complex(double re, double im) {
        this.re = re;
        this.im = im;
    }
 
    public String toString() {
        return "(" + re + " + " + im + "i)";
    }
}
 
class Main {
  public static void main(String args[])
  {
       Complex c = new Complex(10, 15);
       System.out.println("Complex number is " + c);
  }         
}
 

 

Question 4 of 10

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

Question 5 of 10

6. Considerando il seguente frammento di codice:

private Integer fieldOne;
private int fieldTwo;

Con quale valore verranno inizializzate le variabili?

Question 6 of 10

7. Quale sarà l’output del seguente codice
package com;

abstract class demo {

}

class Test {

  public void hello(demo d) {
    if (d instanceof demo)
      System.out.println("istanza di demo");

    if (d instanceof Prova)
      System.out.println("istanza di Prova");
  }
}

public class Prova extends demo {

  public static void main(String[] args) {
    Test obj = new Test();
    Prova p = new Prova();
    obj.hello(p);
  }
}
 

Question 7 of 10

8. Quale sarà l’output prodotto dal seguente codice: 
class Test
{
    public static void main (String[] args) 
    {
        int arr1[] = {1, 2, 3};
        int arr2[] = {1, 2, 3};
        if (arr1.equals(arr2))
            System.out.println("Same");
        else
            System.out.println("Not same");
    }
}
 

Question 8 of 10

9. Quale sarà l’output del seguente codice
public class Prova {
  
  static int count;
  
  public void hello(int r)
  {
    count = r;
    count++;
    
    
  }

  public static void main(String[] args) {
    
    Prova p = new Prova();
    p.count = 30;
    p.hello(40);
    
    Prova p1 = new Prova();
    p1.count = 50;
  }
}
 

 

Question 9 of 10

10. 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 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 *