CSCI 305 Homework 5 Due Date: April 16, 2018 @ Beginning of Class

Name:

Object Orientation 1. Suppose two reference variables x and y have the declared types R and S like this: R x; S y;

When the types guarantee that this is safe (i.e., when S is a subtype of R ), Java will allow the assignment x = y . When neither of these conditions holds, the assignment might or might not be possible at runtime, and Java will permit it only with an explicit type case, x = (R) y . (This kind of type cast is called a downcast) With this explicit type cast, the Java language system performs a runtime check to make sure the exact class of y at runtime is in the type R . Suppose the following Java declarations: class C1 implements I1 { } class C2 extends C1 implements I2 { } class C3 implements I1 { }

where I1 and I2 are two unrelated interfaces neither extending the other, and suppose a variable of each type: C1 c1; C2 c2; C3 c3;

I1 i1; I2 i2;

For each of the following assignments say whether Java allows it, disallows it, or allows it only with a downcast, and explain why. (Hint: An assignment of c1 to i2 is allowed with a downcast, even though the class C1 clearly does not implement interface I2 . Think carefully about why.) c1 = i2

i1 = c1

c1 = c2

c3 = i1

c2 = c3

1. Suppose a derived class C2 defines a method m of type A2->B2 that overrides a method m of type A1->B1 , inherited from the base class C1 . Different languages have very different

rules about how the types A1 and A2 , and B1 and B2 , must be related. Investigate and report on this aspect of inheritance, citing the sources you used. Answer the following questions: What is the rule called covariance? Give an example of a language that uses the covariant rule. Explain the advantage of this rule.

What is the rule called contravariance? Give an example of a language that uses the contravariant rule. Explain the advantage of this rule.

Parameters 1. The following code fragment uses arrays in Java. The first line declares and allocates an array of two integers. The next two lines initialize it. int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0], A[A[0]]);

Function f is defined as: void f(int x, int y) { x = 1; y = 3; }

For each of the following parameter-passing methods, say what the final values in the array A would be, after the call to f . (There may be more than one correct answer.) By value

By reference

By value-result

By macro expansion

By name

CSCI 305 Homework 5 - GitHub

Apr 16, 2018 - The following code fragment uses arrays in Java. The first line declares and allocates an array of two integers. The next two lines initialize it. int[] A = new int[2];. A[0] = 0;. A[1] = 2; f(A[0], A[A[0]]);. Function f is defined as: void f(int x, int y) { x = 1; y = 3;. } For each of the following parameter-passing methods, ...

42KB Sizes 105 Downloads 294 Views

Recommend Documents

CSCI 305 Homework 1 - GitHub
Feb 9, 2018 - 2. What is the name of the paradigm that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data? (1 pt) a. event-driven b. concurrent c. scripting d. object-oriented e. logic f. imperat

CSCI 305 Homework 2 - GitHub
Feb 23, 2018 - Describe how Fortran common blocks work and give an example. What happens if two named common blocks with the same name contain different variables? What is the difference between a blank common and a named common? What does the linker

Homework #1 - GitHub
Please select either bus 2 or 3 as reference bus, calculate the line flows, and check if the results are the same. 2. Come up with a case study of LP, and solve it in ...

Homework 12 - Magnetism - GitHub
region containing a constant magnetic field B = 2.6T aligned with the positive ... With what speed v did the particle enter the region containing the magnetic field?

Operating Systems Homework #3 - GitHub
May 14, 2015 - (Integer) Number indicating scheduling algorithm. 27 int policy;. 28. // Enum values for policy. 29 const short FCFS=0, SJF=1, PRIOR=2, RR=3;.

Homework 22 Physics 2220 - GitHub
Dec 2, 2014 - In order to determine y-component of E-vector, we need to use right-hand rule, which will give us negative sign and for the size we will have.

Operating Systems Homework #2 - GitHub
May 7, 2015 - #include ... unsigned int tick () { // get current time (msec) ... Repeat think-hungry-eating cycle during given execution time in secs.

Lab 5: strataG - GitHub
Let's take Wang (2016)'s advice into account. • To change settings to ... individuals using the software STRUCTURE: a simulation study. Molecular Ecology.

HOMEWORK
Homework​​is one​​of​​the​​options​​parents/legal​​guardians​​have​​to​​support​​their​​child's learning.

Brooklyn Community District 5 - GitHub
Affordable housing. 2. Cultural facilities & programs. 3. Unemployment. To learn more, please read Brooklyn CD 5's · Statements of Community District Needs · and Community Board Budget Requests · for Fiscal Year 2018. A Snapshot of Key Community Indi

Queens Community District 5 - GitHub
of residents 5 years or older have limited · English proficiency. Queens. 18%. 20%. NYC. 21%. Queens CD 5 of residents have incomes below the NYCgov poverty threshold. See the federal poverty rate here. NYCgov POVERTY MEASURE11. Queens. 30%. 25%. NYC

Bronx Community District 5 - GitHub
This metric from the Mayor's Office for Economic Opportunity accounts for NYC's high cost of housing, as well as other costs of living and anti-poverty benefits. Land Use Category. % Lot. Area. # Lots. Click here for a more detailed land use map of B

CSCI E-76 - cdn.cs76.net
. . My title. . . My link. My header. . . Page 7. . .

CSCI E-76 - cdn.cs76.net
. . My title. . . My link. My header. . . Page 7. . .

Manhattan Community District 5 - GitHub
Park. MN 4. MN 6. MN 2. MN 8. Manhattan Community District 5. Neighborhoods1: Flatiron, Gramercy Park, Herald Square, Midtown, Midtown South, Murray Hill, Times Square, Union Square. Top 3 pressing issues identified by. Manhattan Community Board 5 in

Chapter 5 and 6 - GitHub
Mar 8, 2018 - These things are based on the sampling distribution of the estimators (ˆβ) if the model is true and we don't do any model selection. • What if we do model selection, use Kernels, think the model is wrong? • None of those formulas

Summer Homework 2016 Grades 5 to 8.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Summer Home ... 5 to 8.pdf. Summer Homew ... s 5 to 8.pdf. Open.

CSCI 1500 grades.pdf
Chicken little 48.6 F 5 0 9 6 6 - - - - - 125 63 - -. CYH 82.3 B 19 20 16 17 18 19 20 - - - 142 91 - -. Dr.Suess 89.5 B 19 20 19 11 19 19 20 - - - 135 132 - -. Duskie 37.5 F 18 20 16 12 2 - 7 - - - 90 - - -. Funky Monk 97.5 A 20 20 20 19 18 20 20 - -

Digest 305.pdf
Reiznice Ozola Opened Georgia- Latvia Conference on Business ... ship owners will have an oppor- tunity to receive any service relating to the registration of.