Chapter 7 Object Oriented Programming

Object Oriented Programming

is an approach to programming that breaks a program into objects that interact with each other.Breaking the world down into objects and using them together in a way that saves you time and effort potentially by making things reusable.

Classes

Objects are created from templates known as ________. You can think of a ______ as the blue print of a building. An object is the actual "building" that we build based on the blue print.

Access Modifiers

default, public , protected, private______ _________ are like gate keepers, they control who has access to that class. In other words, they control whether other classes can use a particular field or method in that class. Defines what classes can access an attribute or method

Public Class

______ _____means the class can be accessed by any class in the program. class header; indicates a publicly accessible class named "_____

package-private

visible only within its own packagemeans the class sonly accessible to other classes within the same package.

Syntax for declaring a class

AccessModifer class ClassName{//contents of the class//including fields, constructors and methods

PascalCasing

refers to the practice of capitalizing the first letter of each word, including the first . This is the convention we will use when naming classes.

The fields of a Java program are the

attributes

Field

A ______ is simply a variable that is declared inside a class. Like any other variables, they are used to store data.

private field

a field that cannot be accessed from outside the class

public field

allows access to the field from outside the class

package-private by default

If we choose not to state the access level of a class member, it is taken to be ______________ by default

encapsulation

_____________ enables a class to hide data and behavior from other classes that do not need to know about them. This makes it easier for us to make changes to our code in the future if necessary.

Two reasons why we don't want other classes to access fields

1-there is no need for other classes to know about a field. Ex: If a field has a method that calculates something for the class and other classes don't need it. We can change things within the class without it impacting other classes2-We do not want other classes to freely modify them. This helps to prevent fields from being corrupted.

final keyword

The _____ keyword indicates that the value cannot be changed after it is c created. Any variable that is declared as ________ must be initialized at the point of declaration or within the constructor. Is used in several different contexts to define an entity which cannot later be changed.used to denote a variable whose value is contant - can also be used in method declaration to assert that the method cannot be overridden by subclasses

Method

is a code black that performs a certain tasks.

void keyword

To code a method that doesn't return data.This kind of method does not return a value and represents a command.πŸ“•: if the method does not return any result we use the _____ keyword. This keyword, when used in a method header, indicates that the method does not return any value when it is called.Void is something you have to put in when a method doesn't return a value. Ex: This this case the method has no word return in it, so we are not returning any values that we're working on.

Constructor

πŸ“•: A _________ is a block of code (similar to a method) that is used to 'construct' an object from the class template. It always has the same name as the class and is commonly used to initialize the fields of the classa sequence of statements for initializing a newly instantiated objectA method for creating an object in a class.a method that initializes a newly instantiated object

Parentheses

___________ after the method name is where we include the parameters of the method. If the method requires no data we just add a pair of empty __________ after the method name.

Parameters

_____________ are names given to the data that we pass into the method in order for it to perform a task. If there method requires no data we just add a pair of empty parenthesis after the method name.

implementing the method

After we declare the method, we define what it does inside the pair of curly braces that follow. this is known as _________ ___ ______.

calling method or invoking a method

makes a method call that invokes the called method

local variables

variables are local to the method in which they are declared and only exist within the method.

Return keyword

Used to return a value back to the main program from a method.used to return the flow of control to the point immediately following where the method or constructor was calledThe _____________ may not be included with a non-value returning method (void method).

Overloading

The process of creating multiple methods of the same name.You can create two methods of the same name as long as they have different signatures. This is known as __________ . The signature of a method refers to the name of the method and the parameters that it has.

Signature of a method

The ________ of a method refers to the name of the method and the parameters that it has.

Instantiating an object

creating an object of a classπŸ“•: making use of a class to create an objectClassName objectName = new ClassName();class name object name = classname();

Instance

An object is also known as an ________.

Syntax for instantiating an object

ClassName objectName = new ClassName(arguments);

arguments

When a parameter is passed to the method, it is called an ____________.The term _________ refers to any expression within the parentheses of a method/function call. i.e. parameter used in function/method definition.

static keyword

is used to declare members that do not belong to individual objects but to a class itself.used to declare a static variableIndicates a class variable vs. an instance variableAllows you to declare a method without carting an object to access it. You use the class itself. some of the pre-written methods in java are declared as ______Ex: The Arrays class. To access the methods in the Arrays class, we use the name of the class. For instance to use the sort() method, we write Arrays.sort().

When you pass in a primitive type variable,

any change made to the value of the variable is only valid within the method itself. Once the program exits the method, the range is no longer valid

When you pass in a reference the variable,

any change made to the value of that variable is valid even after the method ends.