CS 1331 Exam 2 Terms

studied byStudied by 176 people
0.0(0)
get a hint
hint

type

1 / 78

Tags and Description

79 Terms

1

type

A class is a "____"

New cards
2

Data and methods

What are the two main attributes of a class?

New cards
3

Instance data

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

New cards
4

copy

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

New cards
5

Methods

functions/procedures (behaviors) within the class

New cards
6

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

Return statement

control immediately goes back to call

New cards
8
return;

What is the return statement for a void method?

New cards
9

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

Parameters

Variables passed into a method

New cards
11

Formal paramaters

Names of the parameters in the header declaration

New cards
12

Actual paramaters

Values passed in when running

New cards
13

T

(T/F) Arrays can be parameters

New cards
14

Static methods

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

New cards
15

Non-static methods

Methods that are always called in the context of an object

New cards
16
this

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

New cards
17

Class interface

A group of specified certain methods for outsiders to use

New cards
18

Visibility modifiers

Modifiers that control access

New cards
19
public

Modifier that allows anyone to access instance data and methods

New cards
20
private

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

New cards
21
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

Constructor

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

New cards
23

initialize

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

New cards
24

Scope

The region of a program where variables are accessible.

New cards
25

Overloading

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

New cards
26

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

F

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

New cards
28

T

(T/F) Constructors can be overloaded

New cards
29
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

F

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

New cards
31

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

A

int a; 

What is this an example of?

A. Declaration

B. Initialization

C. Instantiation

New cards
33

A

String s;  

What is this an example of?

A. Declaration

B. Initialization

C. Instantiation

New cards
34

B

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

A. Declaration

B. Initialization

C. Instantiation

New cards
35

C

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

A. Declaration

B. Initialization

C. Instantiation

New cards
36
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
==

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
toString()

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

New cards
39
static

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

New cards
40

In the class

Where is the memory space for static variables located?

New cards
41

F

(T/F) Static methods can reference instance variables

New cards
42
null

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

New cards
43

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

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

T

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

New cards
46

Auto-boxing

Converting a wrapper to a primitive type

New cards
47

Unboxing

Converting a primitive type to a Wrapper

New cards
48

Javadoc

Documenting your code

New cards
49

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
extends

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

New cards
51

is-a

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

New cards
52
super

keyword for denoting access to parent's members

New cards
53
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

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

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

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
@Override

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

New cards
58

F

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

New cards
59

single

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

New cards
60
Object

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

New cards
61
instanceof

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

New cards
62
getClass()

Method that returns the class an object is an instance of

New cards
63
this(xxxx);

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

New cards
64
this.xxxx;

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

New cards
65
this.xxxx();

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

New cards
66
super(xxxx);

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

New cards
67
super.xxxx;

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

New cards
68

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

F

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

New cards
70

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

can

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

New cards
72

F

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

New cards
73
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

Static type

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

New cards
75

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

Dynamic type

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

New cards
77

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

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
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

Explore top notes

note Note
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 11 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 13 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 15 people
Updated ... ago
5.0 Stars(3)
note Note
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 3224 people
Updated ... ago
4.6 Stars(22)

Explore top flashcards

flashcards Flashcard57 terms
studied byStudied by 9 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard66 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard129 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard52 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard39 terms
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard37 terms
studied byStudied by 31 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard58 terms
studied byStudied by 1335 people
Updated ... ago
5.0 Stars(10)
flashcards Flashcard48 terms
studied byStudied by 31 people
Updated ... ago
5.0 Stars(1)