

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this past exam are: Assignment Statement, Logically Equivalent, Independent Statements, Code Fragment, Value of Nag, Public Static, Independent Statements
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


public class Test { public static void main(String[] args) { int x = 1; if (x < 2) System.out.print("Hello, "); if (x > 1) System.out.print("How are you? "); else System.out.println("I am fine."); } }
if( !P && Q )
Location loc1 = new Location( 2, 3 ); Location loc2 = new Location( loc1 ); Location loc3 = loc1;
( loc1 == loc2 ) ____________ loc1.equals( loc2 ) ____________
( loc2 == loc3 ) ____________ loc2.equals( loc3 ) ____________
Quiz2 q2 = new Quiz2();
q2.method1( 5 );
public class Quiz { private int a; // Line 3
public void method1( int x ) { int a; // Line 7 int b = x;
a = b + 2; this.a = b + 3;
System.out.println( "a = " + a ); System.out.println( "b = " + b ); System.out.println( "this.a = " + this.a ); System.out.println( "method2() result = " + method2( x ) ); System.out.println( "this.a = " + this.a ); }
private int method2( int x ) { int a = x; int b = this.a;
b = b + 3;
System.out.println( "a = " + a ); System.out.println( "b = " + b ); System.out.println( "this.a = " + this.a );
this.a = b + 1;
return a + 1; } }