AP Comp Sci Final Review (part I)

AP Comp Sci Final Review (part I)

9th - 12th Grade

12 Qs

quiz-placeholder

Similar activities

Loops

Loops

5th - 12th Grade

16 Qs

Skill Development - Debugging Practice1

Skill Development - Debugging Practice1

10th Grade - Professional Development

10 Qs

For Loop

For Loop

9th - 12th Grade

10 Qs

Single Array

Single Array

11th Grade

10 Qs

Kuis Dadakan ;)

Kuis Dadakan ;)

10th Grade - University

15 Qs

AP CSA Unit 1 & 2 Review

AP CSA Unit 1 & 2 Review

9th - 12th Grade

10 Qs

Unit 4 - Conditions and Logic

Unit 4 - Conditions and Logic

12th Grade

17 Qs

Loops Quiz

Loops Quiz

9th - 12th Grade

16 Qs

AP Comp Sci Final Review (part I)

AP Comp Sci Final Review (part I)

Assessment

Quiz

Computers

9th - 12th Grade

Medium

Created by

Michael Courtright

Used 4+ times

FREE Resource

12 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Class, objects, arrays and Strings are examples of:

nonprimitive data types

primitive data types

inheritance

arrays

recursion

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Downcasting, super(), super, extends, interface and implements are examples of:

nonprimitive data types

primitive data types

inheritance

arrays

recursion

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

enhanced for, nested loop, index and length are examples of:

nonprimitive data types

primitive data types

inheritance

arrays

recursion

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

self-calling, base case and StackOverflowException are examples of:

nonprimitive data types

primitive data types

inheritance

arrays

recursion

5.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

class MCQReview{

int x;

int y;

MCQReview(int x, int y){

this.x = x;

this.y = y; }

void method(){

x += x++ - y/2 + ++y; }

void display(){

System.out.println("x is: " + x);

System.out.println("y is: " + y); }

public static void main(String[] args){

MCQReview m1 = new MCQReview(10,20);

m1.method();

m1.display(); }

}

  What will be the output of the above code segment?

x is: 32

y is: 20

x is: 30

y is: 21

x is: 32

y is: 21

x is: 30

y is: 20

x is: 31

y is: 21

Answer explanation

x = 10, y =20

x += x++ - y/2 + ++y;

According to operator precedence and operator associativity,

x = x+ (x++ - y/2 + ++y);

x = 10 + (10 - 20/2 + 21) // internally y and x are incremented by 1

x = 10 + ( 10 - 10 +21) = 10 + (0 +21) = 31

x ++ will first substitute and then increment, whereas ++y will first increment and then substitute.

6.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

class MCQReview2{

int x; static int y;

void display(){

System.out.println("x is: " + x);

System.out.println("y is: " + y); }

public static void main(String[] args){

MCQReview2 m1 = new MCQReview2();

MCQReview2 m2 = new MCQReview2();

m1.x = 2;

m1.y = 3;

m2.x = 4;

m2.y = 5;

m1.display();

m2.display(); } }

What will be the output of the above code segment?

x is: 4

y is: 3

x is: 4

y is: 5

x is: 2

y is: 3

x is: 2

y is: 3

x is: 2

y is: 5

x is: 4

y is: 5

x is: 2

y is: 4

x is: 3

y is: 5

x is: 2

y is: 3

x is: 4

y is: 5

Answer explanation

x is: 2

y is: 5

x is: 4

y is: 5

The variable y, being static, is a shared copy for all the objects. If one object alters the value, it will modify for both of the objects. The variable x is nonstatic, which means that it is an instance variable, a different copy for different objects.

7.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Assuming that a and b are declared as valid integer values, which of the following is an equivalent statement for the Java statement below?

(x > 5 && x < 8) || (x > 0 || y < 0)

((x > 0) || (x > 5 && x < 8)) || (y < 0)

(x > 5 && x < 8) && (x > 0)

(y < 0) || (x > 5 && x < 8)

(x < 0 && y > 0) && (x < 5 || x > 8)

Answer explanation

((x > 0) || (x > 5 && x < 8)) || (y < 0)

Using the commutative property, the terms can be switched while maintaining the value. The || operator is used with the commutative property, and the expression with && remains together to follow the laws of logic.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?