Comp 1409 Pre-Midterm Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a Java Class and an example?

A

A file that describes a general category in terms of data and behaviours ie a book class describes title, author, date written, that the book can be opened and closed etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an object?

A

One specific instance of a class eg in a book class the object would be the title. Every book will have a title.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are instance variables?

A

an individual piece of data within a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

nouns or adjectives should be used to describe what kind of data?

A

Instance variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 4 primitive data types?

A

int, double , boolean and char

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the reference (or object) data types?

A

String and classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are 2 visibility modifiers (access modifiers) from lesson 2?

A

public or private, accessible from any class or only from within a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

instance variables should always be be private?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a constructor and and what does it do?

A

A constructor is a special method used to initialize objects when an object of a class is created (is called automatically). Is used to set sensible initial values for object attributes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Constructors should be marked public

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Constructors should have Javadoc comments

A

T with @param tags explainging each parameter’s conditions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s the difference between formal arguments and actual arguments

A

Formal arguments are instance variables in a constructor where as an actual argument is the data in the argument. IE formal argument is variable “title” where as the the actual argument would be “Star Wars”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a method?

A

An instruction, a function, a verb

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How should methods be named?

A

As verbs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What must methods always have to compile?

A

a return type even if its void

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Do accessors need the variable return type or should it be void?

A

It should be the same return type as the instance variable that is getting returned

17
Q

Do you think there are usually more getters than setters?

A

I hope so because thats what big boss says

18
Q

Are mutators returning the same variable type as the instance variables they are changing?

A

No they return void

19
Q

What are local variables?

A

defined within a method. Are created when the method called and destroyed when it ends.

  • locals scope only
  • private visibility modifier/no visibility modifier
20
Q

Where are instance variables?

A

Defined within a class. Are created when an object is created and destroyed when the object is destroyed

21
Q

What are static variables?

A

Belong to the class not each object

  • Each object uses the single instance of the instance of the variable
  • Declared with keyword static - public static int population
  • no object required
22
Q

What are static methods

A
belong to a class
can only use class (static) variables not instance variables
Can be called without object instantiation
declared with a static keyword
23
Q

What is the final variables?

A

Instance variables that accept data once and never change

Keyword final

24
Q

Constants - what is they?

A
Data that are only set once 
Declared with static final keywords at class level
used to represent things that dont change (sucha s the value of Pi)
Often called symbolic constants, named with all caps
25
Q

Are a static method and static variable acceptable?

A

Yeeess

26
Q

Are instance method and instance variable acceptable?

A

yes

27
Q

Are instance methods and static variables acceptable?

A

Oh sure, bud

28
Q

Are Static Methods and Instance variables acceptable?

A

Not okay. Not okay at all.

29
Q
If variable is:
Accessible only to the method it is declared in
no access modifier
no default values
It must be what kind of variable?
A

Local

30
Q
Variable is 
Accessible all throughout the class
private
declared within the class
li
A

instance

31
Q

Which operations then assign shoulod you not do? (operation than issign be x += number

A

dont do *=, /=, %=

32
Q

What are the three ways an overloaded constructor can work/be differentiated?

A
  1. ifferent number of parameters
  2. different type of parameters
  3. different order of parameters
33
Q

Whats the formatt for switch/case statements?

A

ublic void printGradeRange(char letterGrade){switch(letterGrade){case(‘A’):case(‘a’):System.out.println(“80 to 100”);break;case(‘B’):case(‘b’):System.out.println(“60 to 79”)
default:
get rekt