Object-Oriented Programming Flashcards
What is an object?
Software rep (abstraction) of real world entity (book) or less tangible concept (bank account). Instance of class. Look at the STATE of you, what USE are you? (state + behaviour)
What is the code for JOptionPane?
JOptionPane: JOptionPane.showMessageDialog() to display info.
JOptionPane.showInputDialog() to ask for user input
What are the types of variables?
Primitives + refs to objects.
Primitive: (Int: byte, short, int, long.) (Float: float, double), char + Boolean.
What is UML?
Unified Modelling Language
What are methods?
Named statement sequences that can be repeatedly executed as required, support code reuse + program clarity/structure. Also used in definition of object behaviour. Data may be shared with methods via parameters, may be defined with formal parameter list, must be called with actual parameter list which matches formal list.
What is an object-oriented program?
Implementation of algorithm to solve problem, contains collection of interacting objects.
What is a string?
Non-primitive type repping sequence of characters, an object. Referenced by identifier e.g. firstName.
If declare string but don’t assignto anything, value is null as doesn’t ref any object. State = char data (len). Behaviour = method calls made via object ref (charAt)
What is instantiation?
The process of creating objects.
What is a class?
Describes state + behaviour of objects of same type. Use UML notation to describe them. Need object class + tester class (with main).
What is an instance variable?
Describes state of objects, methods describe object behaviour. Object must exist before behaviour method used. Static method isn’t associated with object.
What are constructors?
Used in building objects, special methods to initialise object data (instance variables), syntax diff from other methods. Shares class name, no return type. E.g. public Car () {} Can define own constructors, parameter list describes info constructor needs. Can directly assign/modify values of instance variables via object ref. Private prevents direct external access.
What is encapsulation?
Fundamental concept of OOP, describes bundling data + methods to work on data within class. Often involves hiding data (state) of object from ext manip. Involves getters + setters to control how info accessed, all data private unless good reason otherwise.
What is a destructor?
Explicit method, some OOP languages provide this automatically called when object no longer refd. In Java, objects no longer refd garbage collected by system (JRE). Finalise method maybe added to class, called by garbage collection, out of programmer control.
What are strings, accessor methods + mutator methods?
Strings are immutable objects – can’t be changed. Accessor methods e.g. charAt, mutator methods change values. Must protect object integrity.
How do you refer to an object under construction?
Use this. to refer to it e.g. this.studentId = id;
What should we do when inputting int/double values?
Use input.nextLine() to clear scanner + move on to next line.
How do we make array data available to other methods?
Use them as parameters, ref to data copied to method. E.g. public static void display (int values[])
What are exceptions + how do we handle them?
Circumstances that may arise in executing program, without management, program will stop. Use try {} catch {} to handle. Can also use Boolean variable + loop so keep trying until user enters valid value.
What are class variables + class methods?
Variables – single copy available across all class instances. Methods – defined as static, accessed via class name. Underlined in UML.
What can enums include?
Variables + methods, including constructors.