CECS 277

¡Supera tus tareas y exámenes ahora con Quizwiz!

strong (Parent-Child)

A _________ is-a relationship is typically made with classes.

Weak (Is-Kinda)

A __________ is-a relationship indicates you should use an interface.

Implementation

A superclass provides some __________ that a subclass inherits

super();

After creating a default superclass, how would you implement the information from it into a default subclass?

public

All methods in an interface type are automatically _____________.

Abstract Static Default

All methods in an interface type are: (3)

Comparable

All of the Collections Types implement which interface?

extended

An abstract class is useless until it is ______________!

implementing

An interface specifies the behavior that an ____________ class should supply.

ArrayList<String> friends = names;

Copy an ArrayList of Strings. Call the copy "friends" and the original "names."

public abstract class GeometricObject implements Comparable { public abstract double getArea(); public abstract double getPerimeter(); public int compareTo(Object other) { GeometricObject c = (GeometricObject) other; return this.getArea() - c.getArea(); } }

Create the abstract class "GeometricObject" and implement the Comparable interface. Create dummy methods for getArea() and getPerimeter() that return doubles.

public static double average(Measurable[] objects) {

Create the first line of a static method "average" that returns a double and takes a parameter of the Measurable Type called "objects."

ArrayList<String> aList = new ArrayList<String>(10);

Declare a new ArrayList called aList of type String and capacity size 10

abstract public class Animal

Declare the public class Animal as abstract. Don't bother with curly braces, etc.

aList.remove(1);

Erase the data from index 1 of the ArrayList aList.

Object

Every class defined without an explicity extends clause automatically extends which superclass?

May Contain real methods within.

How does an Abstract Class differ from an Interface?

1

How many parent classes can you extend from? (Answer in Numeric Form)

Eliminate redundant methods

In order to minimize dependencies and make efficient classes, what should you attempt to do?

public interface CollegeStudentLivingAtHome { String notification(Person mom); void cleanRoom(); void doHomework(); }

Initiate an interface called CollegeStudentLivingAtHome with the following methods: String notification(Person mom); void cleanRoom(); void doHomework(); }

(The) Process

Interfaces guarantee you'll have a method, but not _________?

Void (Otherwise, may return an informational value)

Mutators are typically what return type?

aList.add(1, "Damian");

Place the String "Damian" at index 1 of the ArrayList aList.

aList.add("Hello");

Place the string "Hello" at the end of the ArrayList aList.

String name = aList.get(2);

Retrieve the data from index 2 of the ArrayList aList and store it in the new String Variable name.

Animal pet = new Dog();

Say we have a superclass Animal and a subclass Dog. Code me a new object using both of these classes.

Animal[] myPets = new Animal[5]; myPets[0] = new Cat(); myPets[1] = new Cat(); myPets[3] = newDog();

Say we have an abstract superclass Animal and subclasses for cats and dogs. Create an array "myPets" of 5 animals where (specifically) index 0 is a cat, index 1 is a cat, and index 3 is a dog.

ArrayList<Animal> mypets = new ArrayList<Animal>(5); myPets.add(0, cat1); myPets.add(1, cat2); myPets.add(3, dog1);

Say we have an abstract superclass Animal and subclasses for cats and dogs. Create an array list "myPets" of 5 animals where (specifically) index 0 is the cat cat1, index 1 is cat cat2, and index 3 is dog1. Work off of the code: Animal cat1 = new Cat(); Animal cat2 = new Cat(); Animal dog1 = new Dog(); Don't worry about the empty indexes, this is all hypothetical.

for (int i = 0; i < myPets.size(); i++) { myPets.feed(); }

Say we have an abstract superclass Animal and subclasses for cats and dogs. You're given the code: ArrayList<Animal> myPets = new ArrayList<Animal>(); Animal cat1 = new Cat(); Animal dog1 = new Dog(); Animal snake1 = new Snake(); myPets.add(cat1); myPets.add(dog1); myPets.add(snake1); Using this as a base, apply the function feed() to all of the animals.

Question q = (Question) obj;

Say you have a variable of Type Object that holds a Question reference. Cast that information into a Question Object.

if (s instanceof BetterRectangle) { BetterRectangle x = (BetterRectangle) s; x.getArea(); x.getPerimeter(); }

Say you have code: Rectangle s = new BetterRectangle(1, 2, 3, 4); Use the getArea() and getPerimeter() methods of the Parent class, Rectangle, on the Child, BetterRectangle. Contain your code within an if statement that checks for BetterRectangle Objects.

public class Student extends Person implements CollegeStudentLivingAtHome { public String notification(String mom) { return "Sent from my iPhone"; } public void cleanRoom() { System.out.println("My room is clean."); } public void doHomework() { System.out.println("I've done my homework."); } }

Say you have code: public interface CollegeStudentLivingAtHome { String notification(Person mom); void cleanRoom(); void doHomework(); } Create a class called Student that includes this code and the superclass "Person." For notification(), return "Sent from my iPhone", for cleanRoom(), print that "My Room is Clean.", and for doHomework(), print that "I've done my homework."

myPets.add(a); myPets.add(b); myPets.add(c); for (Animal p : myPets) { p.feed(); }

Say you have the following code: ArrayList<Animal> myPets = new ArrayList<Animal>(); Animal a = new Cat(); Animal b = new Cat(); Animal c = new Dog(); Add them to the myPets aarray and then call the feed() method on all of them.

Yes

Say you have the following code: ArrayList<String> friends = names; firends.add("Harry"); Will Harry also be in "names?"

public class Birds extends HouseHoldPets { int wingspan; Color feathercolor; int numtalons; public Birds(Color cEyecolor, int cAge, String cName, int cWingspan, Color cFeathercolor, int cNumtalons) { super(Color cEyecolor, int cAge, String cName); wingspan = cWingspan; feathercolor = cFeathercolor; numtalons = cNumtalons; }

Say you have the superclass HouseHoldPets: public class HouseHoldPets { Color eyecolor; int age; String name; public HouseHoldPets(Color cEyecolor, int cAge, String cName) { eyecolor = cEyecolor; age = cAge; name = cName; } } Create a Birds subclass with int wingspan, Color feathercolor, and int numtalons from the HouseHoldPets superclass.

Employee e = new Salary();

Say you've defined a Parent Class Employee and the subclass Salary. Use Polymorphism to create a new Salary Object from an Employee Initialization.

Immutable

Strings are inherently __________________, as no methods exist that change the data within.

public void speak() { System.out.println("Meow!"); }

Suppose your class Mammals has a void method called speak(). Override it within the subclass Cat to perform the String "Meow!" Only write in the method though, not the whole class.

True

T/F: A class can only extend from a single superclass.

False (You can't create a "new" Object of an Abstract Class, but you can still define the constructors, which are used for their subclasses)

T/F: Abstract classes can create Objects.

True

T/F: After you've defined an interface, you have to include every method body specified within it, otherwise you'll get errors.

False (Can't be Contained)

T/F: An abstract method can be contained in a nonabstract class.

False (No Instance Variables)

T/F: An interface has instance variables.

False (You can't construct objects of the Interface Type)

T/F: An interface type has a constructor.

False (Can implement any number of interfaces)

T/F: Classes can only inherit one interface.

True

T/F: In a non-abstract subclass extended from an abstract class, all the abstract methods must be implemented.

True

T/F: It's legal to store a subclass reference in a superclass variable.

False (No Implementation)

T/F: Methods in an interface have a name, parameters, return type, and implementation.

False (Child can always sub for a parent, but not vice versa)

T/F: Parents can always substitute for a Child.

False (You can also call them or add additional data to them)

T/F: You can't override the methods inherited from a parent class.

Super

Thanks to polymorphism, object reference variables can be _____________ classes of the actual object type.

class interface

The ______________ that implements the _________________ can always substitute from the interface type, but not the other way around.

Cohesive

The public interface of a class is _____________________ if all of its features are related to the concept that the class represents.

for (String name : aList) { System.out.println(name); }

Use an enhanced for loop to print out the contents of the String ArrayList aList. Start from: ArrayList<String> aList = new ArrayList<String>();

Fast Standard (Easy to Understand, Structured the same in all)

What are the benefits of Javadoc? (2)

Common Processes

What common factors indicate that you should implement an interface to wrap things up together nicely?

Dynamic Method Lookup

What concept from Polymorphism allow us to treat objects of different classes in a uniform way?

ArrayList

What data type contains methods for insertion and removal of elements?

ArrayList

What data type stores a sequence of values that can change size, and grows and shrinks as needed?

Type Parameter

What do the Angled Brackets (<>) denote in an ArrayList?

Interface

What do we call a collection of constants and abstract methods that can't be instantiated?

Abstract

What do you call any class that has a method in it that doesn't have a method body?

Package

What do you call collections / libraries of related classes?

Polymorphism

What do you call the ability of an Object to take on many forms?

Inheritance

What do you call the mechanism of basing an object or class upon another object or class, retaining similar implementation, in order to derive new classes from existing ones and form them into a hierarchy of classes?

Javadoc

What do you call the process of commenting your code to enable automatic generation of web pages that document your code?

10 (0)

What is the default capacity of an initialized ArrayList? (Also, what's the size when it's first initialized?

extends

What is the key word used by a subclass to indicate that it inherits information from a superclass?

super();

What is the method used to substitute information from a superclass into a subclass' constructor?

Concrete

What is the opposite of an abstract class (basically, a normal class)?

Encapsulation

What is the term that describes when everything within your classes relates solely to the class itself? "Hide the Implementation Details from the Rest of the World"

instanceof

What keyword can you use to use a child's methods on a parent?

Abstract

What keyword do we use to prevent a class from ever being instantiated? (Prevents an object from being created, but can still be referenced for polymorphism).

Wrapper

What kind of class converts primitive data types into objects?

Generic

What kind of class is an ArrayList?

Any

What kind of data can an abstract class contain?

Constant

What kind of data can an interface contain?

Abstract

What kind of method has no body?

Static

What kinds of variables belong to the class, but not to any object of that class?

Private Instance Static

What kinds of variables don't need tags when you're Javadoc-ing? (3)

Override

What occurs when a method in a subclass has the same method name and parameters as that of a parent, but ultimately does something slightly different?

Overload

What occurs when a method in a subclass has the same method name and parameters as that of a parent?

Error

What occurs when you implement 2 different interfaces with the same methods or constants?

Subclass

What should you create when you want to make a more specific version of a class?

Common Things (w/ Parent) (Not limited to variables; methods work too)

What things do you use to define a Child Class / Subclass?

Interface

What types are used to express common operations?

Variables

What types of data should always be declared private to prevent other methods from changing their values?

Overload

When you inherit a toString() from a Superclass and modify the contents and the parameters, what are you doing?

Override

When you inherit a toString() from a Superclass and modify the contents, but not the parameters, what are you doing?

Open

Which Arrowhead is the UML for Inheritance?

Object Superclass

Which Class is the Superclass of every Java Class?

Comparable

Which Interface of the standard Java Library consists solely of the method: int compareTo(Object otherObject);

implements

Which key word indicates that your code includes an Interface?

To modify the arguments passed into a method.Auto

Why do we need a Wrapper Class to convert a primitive data type into an object?

Implements the Interface

You can convert from a class to an interface, so long as ____________________________________.

/** Filler @author Canyon @version 1.0 **/

You've just created a class. Create a Javadoc with the description ("Filler"), credit "Canyon" as the creator, and mark it down as version 1.0.

/** Filler @param age Filler @param participants Filler @return avgAge Filler **/

You've just created a method that takes 2 int parameters for "age" and "participants," then returns int "ageAvg." Create the Javadoc for it, describing it as "Filler" under each category.

Mutator

_____________'s change the state of an object.

Immutable

__________________ classes have no mutators.

Accessor

_________________________'s ask an object to compute a result, without changing the state.


Conjuntos de estudio relacionados

Prep U for Brunner and Suddarth's Textbook of Medical Surgical Nursing, 13th Edition Chapter 36: Management of Patients With Immunodeficiency Disorders

View Set

0121 Real Estate Principles I, Real Estate 1

View Set

Magic Conveyor Belt Book - SCMG 232 Final

View Set

CITI Training - Research Study Design - All Modules

View Set

Chapter 33: Renal System disorders

View Set