2D Arrays/Inheritance

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Given int[ ][ ] grid = new int[5][3], what is the value of grid[0].length?

3

Given the array int [ ] [ ] array = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} } What is array[0][1] + array[2][0]?

9

An example of a Subclass / Superclass relationship would be Dog to...

Animal

When does a method override occur?

Anytime a subclass method signature matches that of the superclass

Given the following code: public class Dog { /* implementation not shown */ } public class MixedDog extends Dog { /* implementation not shown */ } What is the correct way to create an array list to store both MixedDog objects and Dog objects?

ArrayList<Dog> dogs = new ArrayList<Dog>();

If a class does not extend any class, what happens?

By default, we extend the Object class

A 2D double array is declared and initialized to track the terrain of a city park. Each value in the 2D array represents the height of a particular latitude and longitude above sea level. Longitude is represented by the columns in the 2D array and latitude is represented by each row in the 2D array.The creator of this 2D array would like to look at the height of the city park along the longitude 100.0 - what traversal method would make the most sense in order to do so?

Column-Major Order

What types of things do we put in the Superclass?

Common Attributes and Behaviors

True or false: Methods in the Object class are useful as is and seldom need to be overridden.

False

Two classes that have a Superclass/Subclass relationship have <this> type of relationship.

Is A

What does the Object class equals() method compare?

It compares whether two variables are represented by the same object.

How do you find the arr[n].length?

It is the number of elements in the nth row.

What is the length of a 2d array?

It is the number of rows.

When a program runs, how does Java choose which methods to run?

It looks first in the instantiated class, then checks the superclasses if the method is not found.

How does Java determine the order to execute methods between superclasses and subclasses?

Java first looks in a subclass for a method signature. If it is found there, it executes that method. Otherwise it checks the superclass methods

If a superclass constructor exists and a subclass doesn't explicitly call the that constructor, what happens?

Java implicitly calls the no-argument superclass constructor

From a design perspective, what goes in the subclass?

Modified/Overridden methods, additional instance variables specific to the subclass, additional methods specific to the subclass

In order for a program to compile, any method that an object uses ...

Must be defined in the class where the object is declared.

If the Student class and Worker class both extend the Person class, how can you create an array to store 10 objects of any of the three classes?

Person[ ] people = new Person[10];

Define polymorphism

Polymorphism lets a method do different things depending on the type of the object it is called on.

How do you find the value of arr[x][y]?

Start with array that is x - 1 and count over to element y - 1.

What is the proper syntax to initialize an empty 6x6 2D String array?

String[ ][ ] array = new String[6][6];

The super keyword can be used from the subclass for the following:

To call the superclass constructor, to call a public method in the superclass, and to refer to the superclass object

True or False: A subclass can be extended by another class to become a superclass.

True

True or false: Every object created in Java can use the Object class methods since the object class is at the top of the hierarchy.

True

How does a Subclass call the Superclass constructor?

Using the super keyword in the first line of the subclass constructor.

Why do we use the @Override in our code?

When we use it, the compiler checks that we are actually overriding the method we intended to.

Does a Subclass need to have a constructor?

Yes, the subclass has its own constructor, either explicit or implicitly created.

How can you create a 2D double array with 6 rows and 7 columns and assign it to connectFour?

double[ ][ ] connectFour = new double[6][7]

What keyword do we use to establish the inheritance relationship between a subclass and a superclass?

extends

Which is the correct way to construct and assign a 2D array, with 8 rows, to popcorn, but does not have the rows constructed yet?

int[ ][ ] popcorn = new int[8][ ];

Given the following class structure: public class Person { /* implementation not shown */ } public class Student extends Person { /* implementation not shown */ } Which of the following objects can be created? Person obj1 = new Student(); Student obj2 = new Student(); Student obj3 = new Person(); Person obj4 = new Person();

obj1, obj2, obj4

What is the correct syntax to call the superclass constructor?

super(parameters)

Given the following code, what is the correct way for the subclass to call the speak method in the Animal class? public class Animal { public void speak(String sound) { System.out.println(sound); } } public class Dog extends Animal { public void bark( ) { /* Missing code */ } }

super.speak("Bark");

Which of the following methods would you find in the Object class? comparesTo toString override delete

toString

Approximately how many methods are contained in the Object class for us to use?

11

True or False: 'Is A' relationships are symmetrical.

False


Kaugnay na mga set ng pag-aaral

Korean L1 L6: What is This? This is...

View Set

Chapter 28 and 30 ATG & Persian Wars

View Set

en el aeropuerto - imperativo "usted"

View Set

Chapter 23 Risk conditions related to pregnancy

View Set

korean hangul - a, ya, eo, yeo, o, yo, u, yu, eu, i

View Set

Native American History and Culture Quiz 11

View Set

Aggregate Demand and Aggregate Supply

View Set