

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: Initial Value, Equivalent Java Expression, Unix Command, Java Program, Code Fragment, Operators are Used, Produced by Evaluating
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


This quiz is to be taken by yourself with closed books, closed notes, no calculators. (Partial) Operator Precedence Table Operators Associativity
What are the values of x and y (left) and a and b (right) after the following code segments are executed?
What is the equivalent Java expression for the following expression such that no! operators are used?
!( a > 5 && b != -9 ) ____________________________________________
Write the full Unix command to compile this Java program.
This command will produce a file named:
Write the full Unix command to run this as a Java application.
Assume we have correctly written a Program.html file. Write the full Unix command to run the above program as an applet.
x = y =
int x = 2, y = 4;
if ( x++ >= 3 || --y >= 3 ) x = x++ + --y; else x = ++x + y--;
a = b =
int a = 2, b = 4;
if ( a++ >= 3 && --b >= 3 ) a = a++ + --b; else a = ++a + b--;
Location loc1 = new Location( 42, 420 ); Location loc2 = loc1; Location loc3 = new Location( loc2 );
What results would be produced by evaluating the following expressions?
( loc1 == loc2 ) ____________ loc1.equals( loc3 ) ____________
( loc2 == loc3 ) ____________ loc3.equals( new Location( loc2 ) ) ____________
Quiz2 q2 = new Quiz2(); q2.method1( 17 );
public class Quiz { private int a; // Line 3
public void method1( int x ) { int a; // Line 7 int b = x;
a = b % 5; 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 * 2;
System.out.println( "a = " + a ); System.out.println( "b = " + b ); System.out.println( "this.a = " + this.a );
this.a = b + 2;
return a + 2; } }
What is the initial value of a on Line 3? ___________
What is the initial value of a on Line 7? ___________
Output: a = __________ b = __________ this.a = __________ a = __________ b = __________ this.a = __________ method2() result = __________ this.a = __________