Test Java Online

1. Se la variabile c vale 2, data l’istruzione switch( c ){case 1: b =7; case 2: b=10;} quanto vale b dopo la sua esecuzione?
A. 10
B. 7
C. 17

Question 1 of 10

2. Quale sarà l’output prodotto dal seguente codice:
public class Test { 
public static void main(String[] args) 
	{ 
		for (;;) 
			System.out.println("GEEKS"); 
	} 
}
 

 

Question 2 of 10

3. Si può accedere a una variabile non statica da un metodo statico?

Question 3 of 10

4.
Una classe astratta deve avere per avere per forza almeno un metodo astratto?

Question 4 of 10

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

6. Quale sarà l'output del seguente codice:
class Helper 
{ 
	private int data; 
	private Helper() 
	{ 
		data = 5; 
	} 
} 
public class Test 
{ 
	public static void main(String[] args) 
	{ 
		Helper help = new Helper(); 
		System.out.println(help.data); 
	} 
}

Question 6 of 10

7. Quale sarà l’output prodotto dal seguente codice: 
class Point {
  int m_x, m_y;
   
  public Point(int x, int y) { m_x = x; m_y = y; }
  public Point() { this(10, 10); }
  public int getX() { return m_x; }
  public int getY() { return m_y; }
   
  public static void main(String args[]) {
    Point p = new Point();
    System.out.println(p.getX());
  }
}
 

Question 7 of 10

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

Question 8 of 10

9. Considerando il seguente frammento di codice:
private int field;

public DefaultConstructor (int field)       {this.field = field;}

public static void main(String [] args){

DefaultConstructor instanceOne = new DefaultConstructor(1);

System.out.println(“IstanceOneValue: “  +instanceOne.getField());

DefaultConstructor defaultInstance = new DefaultConstructor( );

System.out.println(“DefaultInstanceValue: “+defaultInstance.getField());

}

Public int getField() { return field; }
 

 

Quale output verrà prodotto:

Question 9 of 10

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