inheritance
allows new classes to be created based on existing classes, thus inheriting their properties and behaviour
superclass
class that can be extended to create a subclass; should not access the extra attributes and behaviours of a subclasssubclass
subclass
a class that extends a superclass and inherits its attributes and behaviours
pros of inheritance
code reusability, code maintenance, modularity (promotes breaking down code into smaller, specialized components)
cons of inheritance
tight coupling (difficult to modify base class without affecting derived class), fragile base class
conditional statement
a statement that only executes when a condition is true
while loop
executes a block of code repeatedly as long as a condition is true
iteration statement
statement that repeatedly executes a block of code
code for conditional statements
if (condition) {
code();
}
else {
code();
}
pros of OOP
modularity → makes code easier to modify and maintain
encapsulation → code doesn’t get modified accidentally
inheritance → reduces development time and increases quality of code
cons of OOP
not suitable for smaller projects
makes programs larger and slower
takes more time and effort
stack memory
holds variables and references to objects
heap memory
only holds objects
primitive data type
double: decimal value
int: whole numbers
boolean: true or false
reference data type
string
objects
declaration of a variable
giving a name and data type to a variable
initialization of a variable
giving a starting value to a variable using the assignment operator (=)
literal
a source code representation of a value f.e. binary representation
access modifier
used to set the visibility of classes, variables, constructors, and methods
instance variables
variables defined in a class where each variable represents an attribute of an object
precondition
a condition that must always be true before the execution of a code segment
postcondition
a condition that must always be true after the execution of a code segment
file class
used to read text files
hasNext()
returns true if there is another input
hasNextLine()
returns true if there is another line of input
hasNextInt()
returns true if there is another integer
for loop
a loop that repeats a code segment a given number of times
for loop code
for (int number = 0; number < 5; number++)
enhanced for loop
a for loop for traversing an array
enhanced for loop traversing code code
for (int number = 0; number < nums.length; number++)
enhanced for loop initialization code
int[] nums = {1, 2, 3, 4};
for ( int num : nums){
…}
1d array
a linear structure that holds one or more values of the same data type
element
an item stored in an array
off by one error
occurs when one tries to access an index value that is greater than the length of the array
polymorphism
the ability of an object to perform an action in different ways
initializing an array
DataType[] name = new DataType[length];
int[] scores = new int[5];