{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture5

# Lecture5 - (1 What does the following program print out...

This preview shows pages 1–5. Sign up to view the full content.

(1) What does the following program print out? class Student { int id = 1; String university; public static void main(String [] args) { int x = 0; Student [] st= new Student[4]; while (x < 2) { st st[x] = new Student(); st[x].id = x; st[x].university = "Ryerson"; x =x +1; } null st[3] =st[1]; st[2] =st[0]; st[0] =st[3]; for (int j=0; j<4; j++) System.out.println ("Student["+j +"]:"+st[j].id); } } id =0 “Ryerson” id=1 “Ryerson”

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 (2) What does the following program print out? class Prob1 { int x, y; boolean test() foo { if (x < y) return true; else return false; } public static void main (String [] args) { Prob1 foo = new Prob1(); foo.x = 3; foo.y = 17; if (foo.test()) System.out.println("yes"); else System.out.println("no"); } } X=3 Y=17
3 (3) Given the source code, what is the output? public class CaseTest { public void test(int x) { switch(x) { case 1: System.out.println("One "); case 2: System.out.println("Two "); break; case 3: System.out.println("Three "); default: System.out.println("Do What?"); } } public static void main(String[] args) { CaseTest a = new CaseTest(); a.test(0); a.test(1); } }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document