Classes Flashcards

1
Q

Class

A
  • have behaviors and states
  • template used to instantiate objects. It is also called a type when used with a reference variable. A class used to instantiate an object determines what states and behaviors an object will possess. A class used as the type for a reference variable determines what behaviors of an object can be invoked, and how any variables get initialized.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Access Modifiers

A
  • determine the visibility of states and behaviors to other classes
  • public (all classes)
  • private (only the class its declared in)
  • protected (all classes in the same package or extended)
  • default (only within the same class in which it is declared)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Getters and Setters

A
  • aka accessor and mutator methods
  • getter method returns the value of a variable stored in an object
  • setter method allows the user to change the value of a variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Constructor

A
  • a special method called at instantiation, used to create an object and initialize variables
  • its a block of code executed when a class is instantiated.
  • all classes have at least one constructor
  • same name as the class and no return type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Overloading

A
  • Methods and constructors can be overloaded
  • methods have the same name but have different number and type of parameters
  • we tell methods apart through the input parameters
  • overloaded method must have a different number and/or types of parameters and/or order of parameters
  • overloaded method can throw Exceptions
  • overloaded method can return a different datatype
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

this keyword

A

a keyword in Java that refers to the object in which the keyboard appears

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

Object

A

An instance of a class in memory. In Java, you never interact with objects directly. Instead, you interact with them through their reference, which is the memory address used by the JVM to find a particular object.

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

Reference variable

A

A variable that stores the reference to an object in memory. Just like the type of a primitive variable determines the range of values that a primitive variable can store, the type of a reference variable determines what types of objects a reference variable can store a reference to. When a class is used as the type of a reference variable, that reference can only be used to invoke behaviors of the object that are declared in the class/type.

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

Default constructor

A

if you create a class and don’t specify a constructor the compiler will generate one for you. The one generated is called the default no-arg constructor

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

Object Class

A

-it is the parent class of all classes defined in Java

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

Object toString() method

A
  • gives a string representation of the object

- prints memory address of object by default

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

Object hashCode()

A

-unique identifier of the object

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

Object equals(Object o)

A

used to compare two objects

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

Object finalize()

A

called by the garbage collector for any object instance before it is removed from memory

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

Object clone()

A
  • creates a copy of the object

- creates a new instance of an object with all the properties initialized to the same values

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