(New) CS 1331 Final Exam Review Terms

studied byStudied by 76 people
5.0(1)
get a hint
hint

type

1 / 165

Tags & Description

Studying Progress

0%
New cards
166
Still learning
0
Almost done
0
Mastered
0
166 Terms
1
New cards

type

A class is a "____"

New cards
2
New cards

Data and methods

What are the two main attributes of a class?

New cards
3
New cards

Instance data

Values that are within the class but not within the methods; generally placed at the top of the class

New cards
4
New cards

copy

Each object that gets instantiated for the class gets its own ____ of the instance variables

New cards
5
New cards

Methods

functions/procedures (behaviors) within the class

New cards
6
New cards

body

public double meth1(int var1, int var2) {
double total;
total = var1 * var2;
return total;
}

//What is the content of the method referred to as?
New cards
7
New cards

Return statement

control immediately goes back to call

New cards
8
New cards
return;

What is the return statement for a void method?

New cards
9
New cards

Local variables

Variables declared inside a method, and are only accessible in that method. In other words, the scope of these variables is the method in which they were created.

New cards
10
New cards

Parameters

Variables passed into a method

New cards
11
New cards

Formal paramaters

Names of the parameters in the header declaration

New cards
12
New cards

Actual paramaters

Values passed in when running

New cards
13
New cards

T

(T/F) Arrays can be parameters

New cards
14
New cards

Static methods

Methods that are not called in the context of an object.

New cards
15
New cards

Non-static methods

Methods that are always called in the context of an object

New cards
16
New cards
this

A Java reserved word that is used inside methods. It refers to the object upon which the method was invoked.

New cards
17
New cards

Class interface

A group of specified certain methods for outsiders to use

New cards
18
New cards

Visibility modifiers

Modifiers that control access

New cards
19
New cards
public

Modifier that allows anyone to access instance data and methods

New cards
20
New cards
private

Modifier that only allows the class itself to access instance data and methods (i.e. objects of that class)

New cards
21
New cards
protected

Modifier that allows a subclass to access instance data and methods from its super class, vice versa, and classes within the same package

New cards
22
New cards

Constructor

A special method that is automatically called when objects are instantiated.

New cards
23
New cards

initialize

A constructor's primary use is to _______ instance variables.

New cards
24
New cards

Scope

The region of a program where variables are accessible.

New cards
25
New cards

Overloading

The use of the same name with different paramater lists (types) to create multiple versions of a method

New cards
26
New cards

Method signature

The part of a method declaration that includes the name, along with the paramater type and order.

Example:

meth1(int var1, int var2)
New cards
27
New cards

F

(T/F) A method signature includes the return type of that method

New cards
28
New cards

T

(T/F) Constructors can be overloaded

New cards
29
New cards
this(v1, v2, v3);

What is the proper syntax for a chained constructor call? (use 3 variables, denoting them as v1, v2, v3)

New cards
30
New cards

F

(T/F) A constructor must always have parameters as input

New cards
31
New cards

B

If a constructor for a class is not written, Java provides one for you when you create an object of that class. However, if you provide one with pamaraters, and you create an object with no paramaters, what happens?

A. The object is created with default values, and the code compiles.
B. The compiler will throw an exception.

New cards
32
New cards

A

int a; 

What is this an example of?

A. Declaration

B. Initialization

C. Instantiation

New cards
33
New cards

A

String s;  

What is this an example of?

A. Declaration

B. Initialization

C. Instantiation

New cards
34
New cards

B

int a;
 a = 0; //What does this line represent?

A. Declaration

B. Initialization

C. Instantiation

New cards
35
New cards

C

String s;
s = new String(“Hello”); //What does this line represent?

A. Declaration

B. Initialization

C. Instantiation

New cards
36
New cards
equals()

If we want to check whether two objects contain the same values, what method or operator do we use (hint: primarily used for objects)?

New cards
37
New cards
==

If we want to check whether two objects reference the same data, what method or operator do we use (hint: primarily used for primitive types)?

New cards
38
New cards
toString()

The method invoked when an attempt to print an object of that type occurs

New cards
39
New cards
static

A modifier that creates one copy of a variable or method that is shared by all instances of the class

New cards
40
New cards

In the class

Where is the memory space for static variables located?

New cards
41
New cards

F

(T/F) Static methods can reference instance variables

New cards
42
New cards
null

A reserved word for objects that have no reference; can occur after declaration but no instantiation

New cards
43
New cards

Copy constructor

A special type of constructor that takes in an object of that class and "copies" its contents. When called, an object with the same values as the paramater object will be created.

New cards
44
New cards

Wrapper classes

A class that corresponds to a primitive type. Allows the usage of primitive types as objects. i.e. Integer, Double, etc.

New cards
45
New cards

T

(T/F) Java will automatically convert between primitive and Wrapper when needed

New cards
46
New cards

Auto-boxing

Converting a wrapper to a primitive type

New cards
47
New cards

Unboxing

Converting a primitive type to a Wrapper

New cards
48
New cards

Javadoc

Documenting your code

New cards
49
New cards

Inheritance

The process of deriving a new class from an existing one. Automatically contains some or all of the methods of the original. Can add new ones to it.

New cards
50
New cards
extends

A keyword that denotes that a class is a subclass of a super class; placed in class header

New cards
51
New cards

is-a

What type of hierarchy represents the super-sub class relationship?

New cards
52
New cards
super

keyword for denoting access to parent's members

New cards
53
New cards
super(v1);

What is the proper syntax for calling the constructor of the parent class from the child class? Use "v1" as the variable.

New cards
54
New cards

F

(T/F) When using the super() call in the constructor of the child class, this line of code can appear anyhwere within the body of the constructor.

New cards
55
New cards

T

(T/F) If the first line of a sub-class constructor is not an explicit call to a super class constructor, Java inserts super() automatically.

New cards
56
New cards

Overriding

When a child class defines a method with the same name (and signature) as the parent, child's version overrides the parent's version

New cards
57
New cards
@Override

What is the correct syntax for notifying the compiler of a method override for a child class?

New cards
58
New cards

F

(T/F) Static methods can be inherited and overridden

New cards
59
New cards

single

Java has _____ inheritance; it can extend at most one class

New cards
60
New cards
Object

The class that all classes are ultimately derived from. Contains methods such as equals(), toString(), clone().

New cards
61
New cards
instanceof

keyword that checks if an object is an instance of another class

New cards
62
New cards
getClass()

Method that returns the class an object is an instance of

New cards
63
New cards
this(xxxx);

chained constructor call (use xxxx as param, variable, or method name)

New cards
64
New cards
this.xxxx;

Instance data of object that is being called upon.
(use xxxx as param, variable, or method name)

New cards
65
New cards
this.xxxx();

Calling a method within the class, do not necessarily need "this"
(use xxxx as param, variable, or method name)

New cards
66
New cards
super(xxxx);

calling super class constructor
(use xxxx as param, variable, or method name)

New cards
67
New cards
super.xxxx;

Accessing instance variable from super class. (use xxxx as param, variable, or method name)

New cards
68
New cards

Abstract

a “placeholder;” useful for super and sub classes in which the super class contains a abstract method that must be included in the subclasses.

New cards
69
New cards

F

(T/F) Abstract classes cannot contain non-abstract methods

New cards
70
New cards

T

(T/F) In order for an abstract method to exist, the subclasses must either override the method or be absract themselves.

New cards
71
New cards

can

Abstract methods (can/can’t) have concrete constructors.

New cards
72
New cards

F

(T/F) You can instantiate an abstract class with new()

New cards
73
New cards
final

A keyword that is used to denote that a class cannot be extended, the value of a variable cannot be changed, or that a method cannot be overridden.

New cards
74
New cards

Static type

A variable’s type at compile time; what class the object is declared as

New cards
75
New cards

Person

Suppose a Person class with a constructor and methods is created. Also suppose that a subclass named Student is created and extends Person. Now, suppose we create a Person object p and write the following lines of code.

Person p;
p = new Student(“Mary”, 1);
//What is the static type of p?
New cards
76
New cards

Dynamic type

the type of object a variable references at run-time; the class an object is instantiated as.

New cards
77
New cards

Dentist

Suppose a Person class with a constructor and methods is created. Also suppose that a subclass named Dentist is created and extends Person. Now, suppose we create a Person object p and write the following lines of code (assume “xxxx” are paramaters).

Person p;
p = new Dentist(xxxx);
//What is the dynamic type of p?
New cards
78
New cards

F

(T/F): If you do not write a toString() method for a class and attempt to print an object that is an instance of that class, you will get a compiler error.

New cards
79
New cards
public abstract void method1()

Write the method declaration of an abstract void method that takes no parameters, is public, and is named “method1”.

New cards
80
New cards

Polymorphism

To have many forms. This allows us to deal with diverse (but related) members of a group in a general way.

New cards
81
New cards

yes

Suppose a class Animal is defined, and Bird is another defined class that is a subclass of Animal. Are the following lines of code legal? (yes/no)

Animal a1;
a1 = new Bird();
New cards
82
New cards

no

Suppose a class Animal is defined, and Bird is another defined class that is a subclass of Animal. Are the following lines of code legal? (yes/no)

Animal a1;
Bird b1 = new Animal();
New cards
83
New cards

T

(T/F) We can assign or subsittute a member of a subclass for a memer of a parent class, but not vice versa

New cards
84
New cards

Dynamic binding

Binding of which type of object is “in there” and influences the call is is deferred until run-time; Compiler simply insures either way is legal.

New cards
85
New cards

dynamic

Suppose obj is an instantiated object of some subclass, and meth() is a method that exists in both the parent and super class. The method that was invoked on a obj.meth() call is determined by the ____ run-time type of obj.

New cards
86
New cards

lowest

In a chain of multiple subclasses, whatver class is ____ in hierarchy determines which methods are called.

New cards
87
New cards

F

(T/F) You cannot cast an object down the hierarchy (casting parent to a child)

New cards
88
New cards

T

(T/F) It is possible for valid casts to fail at run-time.

New cards
89
New cards

Generics

Classes and method definitions with types. You write a _____ class/method, then it can be created to handle any different type of object.

New cards
90
New cards

ArrayList

Like an array, like a list (can grow in size).

New cards
91
New cards
import java.util.ArrayList;

Write the line of code that imports an ArrayList for use.

New cards
92
New cards
ArrayList<Type> list = new ArrayList<>();

How do you correctly declare and instantiate an ArrayList? Use “Type” and “list” in your answer when appropriate.

New cards
93
New cards

to the right

When you add an object to an ArrayList at a particular index, which way does the rest of the list shift?

New cards
94
New cards

Interfaces

Specification of a set of abstract behaviors (methods). Classes choose to provide these behaviors and then advertise themselves as doing so.

New cards
95
New cards

F

(T/F) A class does not have to implement every method in the interface it implements.

New cards
96
New cards

T

(T/F) A class can have other methods besides the ones it implements from an interface.

New cards
97
New cards

F

(T/F) An interface is a class.

New cards
98
New cards

T

(T/F) Interfaces can be in hierarchies

New cards
99
New cards

Recursion

One made to same method as resident in; The process of calling a method within the method itself.

New cards
100
New cards

F

(T/F) Recursive calls are essentially “calling yourself”

New cards

Explore top notes

note Note
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 12 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 22 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 28 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 6 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 2008 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 10 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)

Explore top flashcards

flashcards Flashcard39 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard308 terms
studied byStudied by 16 people
Updated ... ago
4.0 Stars(1)
flashcards Flashcard42 terms
studied byStudied by 21 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard74 terms
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard64 terms
studied byStudied by 36 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard71 terms
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard60 terms
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard342 terms
studied byStudied by 70 people
Updated ... ago
5.0 Stars(1)