Search Header Logo

AP Comp Sci Final Review (part I)

Authored by Michael Courtright

Computers

9th - 12th Grade

Used 5+ times

AP Comp Sci Final Review (part I)
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

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.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?