OOP - Week 3 Flashcards
What is a Class
A class is a set of instructions that describe how an object can behave and what information it contains
What are some pre-defined classes
System, Integer, String, Arrays, Math
What is a class made of
Fields - variables
Methods - functions
Constructors - to initialise objects
Class syntax
public class name { //code }
Access Modifiers
public - accessed everywhere
protected - same package and subclasses
no modifier - same package
private - its own class
What is a constructor
A special method used to initialise objects and fill out the class template
Constructor syntax
public (classname) (variables)
Escape sequence character
Backslash
What must be different to make several constructors in one object
Number of parameters or datatype
Key string methods
String concat(String str) char charAt(int index) int length() String trim() booleanStartsWithStr(String str)
What does it mean if printing a line outputs I@…
The object can be passed as a reference
How to compare the actual value of a string
str1.equals(str2)
How to compare alphabetic order between strings
str1.compareTo(str2)
What is the scanner class
Enables a program to read data for use in a program
How to use the scanner class
import java.util.Scanner;
Add a public scanner class