AP Comp Sci Unit 20

¡Supera tus tareas y exámenes ahora con Quizwiz!

What would fix line 1 correctly ? class G{ private int x; public G() { x=3;} public void setX(int val){ x=val; } public String toString(){ return ""+x; } } class H extends G{ private int y; public H() { y=4;} public void setY(int val){ y=val; } public String toString() { return ""+y+super.toString(); } } //test code in the main method G bad = new H(); bad.setY(9); //line 1

((H)bad).setY(9);

Whats the output for line 2 ? class J{ private int x, y; public J() { x = y = 3;} public void fun() { x = y = 6; } public int back() { return 1; } public String toString() { return x + " " + y; } } class K extends J { public void fun() { out.println(back()); } public String toString() { return "class K " + super.toString(); } } //test code in the main method J runner = new J(); runner.fun(); out.println(runner); //line 1 runner = new K(); out.println(runner.fun()); //line 2 out.println(runner); //line 3

1

Whats the output for line 1 ? class G{ private int x=9; public G() { x=11;} public void setX(int val){ x=val; } public String toString(){ return ""+x; } } class H extends G{ private int y; public H() { y=4;} public void setY(int val){ y=val; } public String toString() { return ""+y+" "+super.toString(); } } //test code in the main method G tester = new G(); out.println(tester); //line 1 tester.setX(4); out.println(tester); //line 2 H sub = new H(); sub.setX(3); sub.setY(11); out.println(sub); //line 3

11

Whats the output for line 3 ? class G{ private int x=9; public G() { x=11;} public void setX(int val){ x=val; } public String toString(){ return ""+x; } } class H extends G{ private int y; public H() { y=4;} public void setY(int val){ y=val; } public String toString() { return ""+y+" "+super.toString(); } } //test code in the main method G tester = new G(); out.println(tester); //line 1 tester.setX(4); out.println(tester); //line 2 H sub = new H(); sub.setX(3); sub.setY(11); out.println(sub); //line 3

11, 3

What is the output for line 4 ? //code in the main of another class Whale flipper = new Beluga(); System.out.println(flipper); //line 1 flipper = new Whale(); flipper = new Beluga(); System.out.println(flipper); //line 2 flipper = new Whale(); flipper.fun(); System.out.println(flipper); //line 3 flipper = new Beluga(); flipper.fun(); //line 4 System.out.println(flipper); //line 5

2

What's the Output for Line 1 class A{ private int x=9; public A() { x=3;} public String toString() { return ""+x; } } class B extends A{ private int x=6; } //test code in the main method A one = new A(); out.println(one); //line 1 one = new B(); out.println(one); //line 2

3

Whats the output for line 2 class E{ private int x=12; public E() { x=9;} public E(int val){ x=val; } public String toString() { return ""+x; } } class F extends E{ public F(){ } public F(int num){ super(num); } } //test code in the main method E three = new E(); out.println(three); //line 1 three = new F(3); out.println(three); //line 2 three = new F(9); out.println(three); //line 3

3

Whats the output for line 3 ? class C{ private int x=12; public C() { x=6;} public void setX(int val){ x=val; } public int getX(){ return x; } public String toString() { return ""+getX(); } } class D extends C{ } //test code in the main method C two = new C(); out.println(two); //line 1 two = new D(); two.setX(6); out.println(two); //line 2 two.setX(3); out.println(two.getX()); //line 3

3

Whats the output line 2 class A{ private int x=9; public A() { x=3;} public String toString() { return ""+x; } } class B extends A{ private int x=6; } //test code in the main method A one = new A(); out.println(one); //line 1 one = new B(); out.println(one); //line 2

3

What is the output for line 4 } public void fun() { x=3; y=5; } public double go() { return x; } public void back() { super.back(); } public String toString() { return super.toString() + " " + x; } } //code in the main of another class Cat fred = new Cat(); System.out.println(fred.go());//line 1 fred.back(); System.out.println(fred); //line 2 fred = new Lion(); System.out.println(fred); //line 3 fred.fun(); System.out.println(fred.go());//line 4 fred.back(); System.out.println(fred); //line 5

3.0

Whats the output for line 2 ? class G{ private int x=9; public G() { x=11;} public void setX(int val){ x=val; } public String toString(){ return ""+x; } } class H extends G{ private int y; public H() { y=4;} public void setY(int val){ y=val; } public String toString() { return ""+y+" "+super.toString(); } } //test code in the main method G tester = new G(); out.println(tester); //line 1 tester.setX(4); out.println(tester); //line 2 H sub = new H(); sub.setX(3); sub.setY(11); out.println(sub); //line 3

4

What is the output for line 5 ? } public void fun() { x=3; y=5; } public double go() { return x; } public void back() { super.back(); } public String toString() { return super.toString() + " " + x; } } //code in the main of another class Cat fred = new Cat(); System.out.println(fred.go());//line 1 fred.back(); System.out.println(fred); //line 2 fred = new Lion(); System.out.println(fred); //line 3 fred.fun(); System.out.println(fred.go());//line 4 fred.back(); System.out.println(fred); //line 5

5 5 3

What is the output for line 3 ? class Cat { private int x, y; public Cat() { x=y=5; } public void fun() { x=7; } public double go() { return x; } public void back() { fun(); } public String toString() { return x + " " + y; } } class Lion extends Cat { private int x,y; public Lion() { x=9; y=7;

5 5 9

What is the output for line 1 ? class Cat { private int x, y; public Cat() { x=y=5; } public void fun() { x=7; } public double go() { return x; } public void back() { fun(); } public String toString() { return x + " " + y; } } class Lion extends Cat { private int x,y; public Lion() { x=9; y=7;

5.0

Whats the output for line 1 ? class C{ private int x=12; public C() { x=6;} public void setX(int val){ x=val; } public int getX(){ return x; } public String toString() { return ""+getX(); } } class D extends C{ } //test code in the main method C two = new C(); out.println(two); //line 1 two = new D(); two.setX(6); out.println(two); //line 2 two.setX(3); out.println(two.getX()); //line 3

6

Whats the output for line 2 ? class C{ private int x=12; public C() { x=6;} public void setX(int val){ x=val; } public int getX(){ return x; } public String toString() { return ""+getX(); } } class D extends C{ } //test code in the main method C two = new C(); out.println(two); //line 1 two = new D(); two.setX(6); out.println(two); //line 2 two.setX(3); out.println(two.getX()); //line 3

6

What is the output for line 3 ? class Whale { private int x, y; public static int c; public Whale() { c++; } public void fun() { x = 6; } public int back() { return 1; } public String toString() { return x + " " + y + " " + c; } } class Beluga extends Whale { public void fun() { System.out.println(back()); } public int back() { return 2; } public String toString() { return "class Beluga " + super.toString(); } }

6 0 4

Whats the output for line 1 ? class J{ private int x, y; public J() { x = y = 3;} public void fun() { x = y = 6; } public int back() { return 1; } public String toString() { return x + " " + y; } } class K extends J { public void fun() { out.println(back()); } public String toString() { return "class K " + super.toString(); } } //test code in the main method J runner = new J(); runner.fun(); out.println(runner); //line 1 runner = new K(); out.println(runner.fun()); //line 2 out.println(runner); //line 3

6 6

What is the output for line 2 ? class Cat { private int x, y; public Cat() { x=y=5; } public void fun() { x=7; } public double go() { return x; } public void back() { fun(); } public String toString() { return x + " " + y; } } class Lion extends Cat { private int x,y; public Lion() { x=9; y=7;

7 5

Whats the output for line 1 ? class E{ private int x=12; public E() { x=9;} public E(int val){ x=val; } public String toString() { return ""+x; } } class F extends E{ public F(){ } public F(int num){ super(num); } } //test code in the main method E three = new E(); out.println(three); //line 1 three = new F(3); out.println(three); //line 2 three = new F(9); out.println(three); //line 3

9

Whats the output for line 3 ? class E{ private int x=12; public E() { x=9;} public E(int val){ x=val; } public String toString() { return ""+x; } } class F extends E{ public F(){ } public F(int num){ super(num); } } //test code in the main method E three = new E(); out.println(three); //line 1 three = new F(3); out.println(three); //line 2 three = new F(9); out.println(three); //line 3

9

What is the output for line 2 ? public class V{ public void one(){ System.out.print("Vone"); } public void two(){ System.out.print("Vtwo"); } } public class W extends V{ public void one(){ System.out.print("Wone"); } public void two(){ System.out.print("Wtwo"); } public void testIt(){ one(); super.two(); } } //code in the main of another class W codeTest = new W(); codeTest.one(); //line 1 codeTest.testIt(); //line 2

BoneVtwo

What is the output for line 1 ? public class V{ public void one(){ System.out.print("Vone"); } public void two(){ System.out.print("Vtwo"); } } public class W extends V{ public void one(){ System.out.print("Wone"); } public void two(){ System.out.print("Wtwo"); } public void testIt(){ one(); super.two(); } } //code in the main of another class W codeTest = new W(); codeTest.one(); //line 1 codeTest.testIt(); //line 2

Wone

What is the output for line 1 ? public class X{ public void one(){ System.out.print("Xone"); } public void two(){ System.out.print("Xtwo"); } } public class Y extends X{ public void one(){ System.out.print("Yone"); } public void two(){ System.out.print("Ytwo"); } public void testIt(){ one(); super.one(); two(); super.two(); } } //code in the main of another class Y code = new Y(); code.one(); //line 1 code.testIt(); //line 2

Yone

What is the output for line 2 ? public class X{ public void one(){ System.out.print("Xone"); } public void two(){ System.out.print("Xtwo"); } } public class Y extends X{ public void one(){ System.out.print("Yone"); } public void two(){ System.out.print("Ytwo"); } public void testIt(){ one(); super.one(); two(); super.two(); } } //code in the main of another class Y code = new Y(); code.one(); //line 1 code.testIt(); //line 2

YoneXoneYtwoXtwo

What is wrong with line 1 ? class G{ private int x; public G() { x=3;} public void setX(int val){ x=val; } public String toString(){ return ""+x; } } class H extends G{ private int y; public H() { y=4;} public void setY(int val){ y=val; } public String toString() { return ""+y+super.toString(); } } //test code in the main method G bad = new H(); bad.setY(9); //line 1

You can not call an H method on a G reference

What is the output for line 1 class Whale { private int x, y; public static int c; public Whale() { c++; } public void fun() { x = 6; } public int back() { return 1; } public String toString() { return x + " " + y + " " + c; } } class Beluga extends Whale { public void fun() { System.out.println(back()); } public int back() { return 2; } public String toString() { return "class Beluga " + super.toString(); } }

class Beluga 0 0 1

What is the output for line 2 ? class Whale { private int x, y; public static int c; public Whale() { c++; } public void fun() { x = 6; } public int back() { return 1; } public String toString() { return x + " " + y + " " + c; } } class Beluga extends Whale { public void fun() { System.out.println(back()); } public int back() { return 2; } public String toString() { return "class Beluga " + super.toString(); } }

class Beluga 0 0 3

What is the output for line 5 ? //code in the main of another class Whale flipper = new Beluga(); System.out.println(flipper); //line 1 flipper = new Whale(); flipper = new Beluga(); System.out.println(flipper); //line 2 flipper = new Whale(); flipper.fun(); System.out.println(flipper); //line 3 flipper = new Beluga(); flipper.fun(); //line 4 System.out.println(flipper); //line 5

class Beluga 0 0 5

Whats the output for line 3 ? class J{ private int x, y; public J() { x = y = 3;} public void fun() { x = y = 6; } public int back() { return 1; } public String toString() { return x + " " + y; } } class K extends J { public void fun() { out.println(back()); } public String toString() { return "class K " + super.toString(); } } //test code in the main method J runner = new J(); runner.fun(); out.println(runner); //line 1 runner = new K(); out.println(runner.fun()); //line 2 out.println(runner); //line 3

class K 3 3

What allows for one class to extend to another class ?

extends

What would fill in blank 1 to complete the S to sstring() method ? public class R { private int one; public R(){ one=0; } public String toString(){ return "" + one; } } public class S extends R { private int two; public S() { two=1; } public String toString(){ <blank 1> } }

return super.toString() + "" +two;

What would be placed in to blank 1 to complete method SetEM() so that one would be assigned the value of n1? public class T { private int one; public T(){ one=0; } public void setOne(int x){ one=x; } } public class U extends T { private int two; public U() { two=1; } public void setEm(int n1, int n2) { two=n2; <blank 1> } }

setOne(n1);

What reserved word can be used when calling a parent class method ?

super

Whats goes into line 1 ? public class N { private int one; public N(){ one=0; } public N(int num){ one=num; } } public class O extends N { public O() { <blank 1> } }

super ();

What would be placed in blank 1 to pass x to the appropriate parent constructor ? public class P { private int one; public P(){ one=0; } public P(int num){ one=num; } } public class Q extends P { public Q() { } public Q(int x){ <blank 1> } }

super(x);

What word can be used when accessing a class as a whole ?

this

What would go into blank 1 ? public class M { private int x; public M(){ x=0; } public M(int x){ <blank 1> } }

this.x=x;

What is the output ? Object a = new String("Hello"); String b = "Hello"; System.out.println(a.equals(b));

true

What is the output ? Object c = new String("Hello"); String d = new String("Hello"); System.out.println(c.equals(d));

true


Conjuntos de estudio relacionados

Disability Income and Related Insurance Quiz

View Set