Limited time offer 20% OFF StudySoup Subscription details

CS 122 - CS 122, Midterm 1 Study Guide - Study Guide

Created by: Laurie Delinois Elite Notetaker

> > > > CS 122 - CS 122, Midterm 1 Study Guide - Study Guide

CS 122 - CS 122, Midterm 1 Study Guide - Study Guide

This preview shows pages 1 - 2 of a 5 page document. to view the rest of the content
background image Computer Programming 122: Midterm 1 Study Guide 
Creating Subclasses/Inheritance 
In Java,  a  class is to an object  what a  blueprint is to a house  establishes the characteristics and behaviours of an object, but does not reserve 
memory space for variables 
Classes are the  plan,  objects  embody  the plan  Inheritance: the process of deriving a new class from an existing one  Through inheritance, new classes automatically contain variables and methods from 
the original class 
*One purpose of inheritance is to reuse existing software*  Word “class” comes from idea of classifying groups of objects with similar characteristics 
(E.g.  Mammals  class would describe mammals as warm blooded, having hair, producing 
milk, etc.) 
Subset/subclass of Mammals would be specific mammals such as Horses or Bears 
 these would inherit the same variables/traits as the Mammals class  Inheritance creates an is-a relationship between child and parent classes  Child classes are specific versions of the parent classes 
 Inheritance is one way: parent classes cannot use variables or methods from child  classes 
The  protected  Modifier: 
Visibility modifiers are used to control access to the members of a class  public methods/variables can be referenced in child classes through objects in the 
child class 
private methods and variables cannot be referenced in the child class or through 
objects of the child class 
Allowing classes to declare public visibility so subclasses can reference it violates 
principle of encapsulation (encapsulation keeps the variables of a class hidden from 
other classes)  
-Solution:  protected  Modifier  protected  modifier allows subclasses to reference variables from parent class while 
retaining some encapsulation properties 
 not as invisible as private, but more shielded than public  *protected visibility provides best possible encapsulation that permits inheritance*  The  super  Reference: 
super   can be used in a class to refer to its parent class  This reference can access a parent’s members  What  super  refers to depends on the class in which it is used  super can be used to invoke a parent’s constructor  It is especially used because parent constructors are not inherited, so they cannot be 
directly invoked 
background image *Using  super  reference will make it so that changes made in a parent class will show in the 
child class 
Child classes can have either single inheritance (derived from one parent) or multiple 
inheritance (derived from more than one parent) 
Child classes’ constructors are responsible for calling parent constructors  Usually super reference is used in the first line of a constructor to call to a parent 
This ensures parent classes’ variables are initialized in the child class 
 super reference can only be done in a child constructor, and must be in the first  line of the constructor 
*Side note: Child classes are able to indirectly reference their parent class’s private 
final Method:  final Method: indicates that a method cannot be overridden or hidden  Basically a promise that the method will always work as designed/implemented  Creates a functionality that cannot be changed by subclasses   
Overriding Methods: 
Child classes are able to override methods derived from a parent class to give the inherited 
method new definition/meaning 
*There are variables called “shadow” variables that contain the same name as variables created in 
the parent class (this should be avoided so as not to create confusion) 
Abstract Classes: 
Abstract classes are classes containing abstract methods  These methods are declared but not implemented  Abstract classes cannot be instantiated but need subclasses to carry out their methods   Its methods cannot be defined as  final  or  static   
 Class Hierarchies 
Child classes can be the parents of other child classes  This creates a class hierarchy  Two or more child classes deriving from the same parent are called siblings  Common features should be put as high in the hierarchy as is reasonable   This helps prevent the creation of redundant class members  Allows developers/coders to add specific characteristics to the child classes that 
make them differ from their parent and sibling classes 
 This increases the potential for code to be reused    Maintenance is made easier, as changes made in a parent classes are passed down 
to child classes automatically 

This is the end of the preview. Please to view the rest of the content
Join more than 18,000+ college students at Pace University - New York who use StudySoup to get ahead
School: Pace University - New York
Department: OTHER
Course: CS 122: Computer Programming II
Professor: Teresa Brooks
Term: Spring 2018
Tags: Inheritance, polymorphism, Searching, and Sorting
Name: CS 122, Midterm 1 Study Guide
Description: This study guide covers information needed for the upcoming midterm.
Uploaded: 02/20/2018
5 Pages 46 Views 36 Unlocks
  • Better Grades Guarantee
  • 24/7 Homework help
  • Notes, Study Guides, Flashcards + More!
Join StudySoup for FREE
Get Full Access to pace - CS 122 - Study Guide - Midterm
Join with Email
Already have an account? Login here
Log in to StudySoup
Get Full Access to pace - CS 122 - Study Guide - Midterm

Forgot password? Reset password here

Reset your password

I don't want to reset my password

Need help? Contact support

Need an Account? Is not associated with an account
Sign up
We're here to help

Having trouble accessing your account? Let us help you, contact support at +1(510) 944-1054 or

Got it, thanks!
Password Reset Request Sent An email has been sent to the email address associated to your account. Follow the link in the email to reset your password. If you're having trouble finding our email please check your spam folder
Got it, thanks!
Already have an Account? Is already in use
Log in
Incorrect Password The password used to log in with this account is incorrect
Try Again

Forgot password? Reset it here