12 - AP CSA - random ap review

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/28

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

29 Terms

1
New cards

Animal = new Dog();

if the method catch() is in the Dog class and the Animal class, which class does it run the method from?

The Dog method

2
New cards

If using super() to call a parent class constructor, where do you put it in the subclass constructor?

It has to be the first line

3
New cards

Do you have to initialize instance variables that are primitive data types?

No, if you forget to initialize them in a constructor, because they are primitive, they will set themselves to a default value

4
New cards

Can you use methods to initialize instance variables to a value in a constructor? (The methods and constructor are part of the same class)

yes

5
New cards

Do subclasses inherit the parent class’s constructor?

no

6
New cards

What kind of methods are equals(), lessThan() and toString()?

Accessor method

7
New cards

System.out.println(this) == toString() ?

yes

8
New cards

What is a NullPointer Exception?

runtime exception, when an object does not point to anything (null)

9
New cards

When are two objects considered aliases?

when. they both reference the same object

10
New cards

what are algorithms?

 step by step process that describes how to solve a problem in a way that always gives a correct answer

11
New cards

What is the running part of a class called?

public void static main(String[] args)

12
New cards

for ap cs a, classes and constructors are private/public and only instance variables are private/public

public, private

13
New cards

Can you call Math.sqrt(x) on x if it is a Double (wrapper class) instead of double (primitive)? Can it be called on an Integer or int?

No, it has to be called on a double, the wrapper class doesn’t count. It can be called on an int, because it will implicitly convert it but not the Integer wrapper class.

14
New cards

How do you get the primitive value of a Wrapper class object?

.intValue() or the wrapper class equivalent

15
New cards

How would you box the Double 3.0 to a double?

double x = Double.doubleValue();

16
New cards

Double x = 3.4;

double y = 2.3;

Is System.out.println(x) == System.out.println(y);

yes, it prints the same thing

17
New cards

If you add 1 to an Integer at its max or subtract 1 from an Integer at its min, what happens?

The int will wrap around to the min or max

18
New cards

Autoboxing

Automatic conversion that the Java compiler makes between primitive types and their corresponding object wrapper classes (ex: int → Integer)

19
New cards

Unboxing

Automatic conversion that the Java compiler makes between object wrapper classes and their corresponding primitive types (ex: Integer → int)

20
New cards

When does Java apply Autoboxing?

  1. When primitive types are psased as parameters of their corresponding wrapper class

  2. when primitives are assigned to a variable of the type of their corresponding wrapper class

21
New cards

When does Java apply unboxing?

  1. When wrapper class types are passed as parameters of their corresponding primitive type

  2. when wrapper class types are assigned to a variable of their corresponding primitive type

22
New cards

Reference types only store ________

references (ex: String, ArrayList, Integer)

23
New cards

Pair p1 = new Pair(2, 3)

Pair p2 = new Pair(2, 3)

p1.equals(p2) = t/f?

false
.equals() has to be overridden for the Pair class, otherwise it just checks to see if p1 and p2 reference the same thing

24
New cards

Overloaded constructor

set default values to something else, this constructor has parameters

25
New cards

What happens if you don’t write a constructor for a class?

Java will write a no-argument constructor for it

26
New cards

What are the standard Java default values if the instance variables are not initialized?

int = 0

double = 0.0

boolean = false

Strings and other objects = null

27
New cards

What if an accessor or mutator method tries to run on a String or other object that hasn’t been initialized?

might be a nullPointer exception for accessor, but def for mutator

28
New cards

What is the difference between methods that return primitive types vs. methods that return reference types?

primitive types: returns a copy, so the original is not changed

reference types: Java returns a copy of the object reference, not the value itself (saves space)

29
New cards

What are the 5 parts of a method header? Name an example.

Access level (public/private), return type (primitive/reference/void), identifier (name of method), parameter list

ex: public void main (String[] args)