01 Prelim CP2 Flashcards
a programming methodology that
defines objects whose behaviors and
interactions accomplish a given task
Object-Oriented Programming
> represents either a REAL-WORD OBJECT or
an ABSTRACTION
> has CHARACTERISTICS or ATTRIBUTES
- Attributes are what objects POSSESS or HAVE
> has STATES
> has BEHAVIOR (METHODS)
> Example: Car
Object
> defines a KIND of object
> a BLUEPRINT for DEFINING the objects
Class
> enables NEW objects to take on the
PROPERTIES of existing objects
> used to AVOID REPETITIION of programming instructions for each class
> makes use of the EXTENDS keyword
Inheritance
Under Inheritance:
> (1)______ is used as the basis of
inheritance.
(2)_______ inherits from a superclass.
Usage:
public class Car extends Vehicle
Superclass: Vehicle
Subclass: Car
- Superclass
- Subclass
What sample of code syntax is this:
/**An _______ for methods that return the
parameter and area of an object **/
public interface Measurable
{
//Returns the perimeter public double getPerimeter(); //Returns the area public double getArea();
}
Interface sample syntax
> contains the HEADINGS for a NUMBER of PUBLIC METHODS
> can also define PUBLIC NAMED CONSTANTS
> uses the keyword IMPLEMENTS
SYNTAX:
public interface Interface_Name
USAGE:
public class Rectangle implements Measurable
Interface: Measurable
Interface
Syntax for Interface:
public interface Interface_Name
Sample usage of Interface:
public class Rectangle implements Measurable
> a COLLECTION of related classes and
interfaces that have been GROUPED
together into a FOLDER
> used with the IMPORT keyword
Package
Syntax for package:
package package _name;
PACKAGE
Note: It typically consists of all (1)______
letters, often punctuated with the (2)_____
symbol.
Sample:
package java.util;
- lowercase
- Dot
Package
Syntax for the import statement:
import package_name.class_name_or_asterisk;
Package sample usage:
import java.util.Scanner;
import java.util.*;
What keyword should you use for Inheritance?
extends
What keyword should you use for Interface?
implements
What keyword should you use for the package?
import
The data type of an object is the name of its ________.
Example Object: Car
Example Object of the same kind: Motorcycle, Truck and
Bus
Class
Objects of the same kind are said to have the same (1)_____ ____ and belong to the same (2)_____.
- Data type
- Class
Example Object: Car
Example Object of the same kind: Motorcycle, Truck and Bus
What is the name of its class?
Vehicle
You can use all the classes that are in a package within any program or class definition by placing an _______ statement.
Import
For the package/import statement:
Is it a requirement to have the class in the same folder with the classes in the package?
NO. The class DOES NOT NEED to be in the same folder with the classes in the package.