Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OO Program question. 1.What are the policies of Java and C++ surrounding covaria

ID: 3708295 • Letter: O

Question

OO Program question.

1.What are the policies of Java and C++ surrounding covariance, contravariance and nonvariance?

2.Define inheritence by generalization. What is abetter OO solution to a situation using this form of inheritance?

3.Describe two situations when using separate compilation in C++ which require you to #include a header file.

4.What is the role of the Class Object in ruby? Suppose you define a class called MyClass. What is the type of the Class Object in ruby for MyClass?

5.Ruby is a dynamic object-oriented programming language. Name and briefly describe two features of ruby that are

more dynamic than C++ or Java. Use any technical terms that are appropriate.

6.Suppose you have the following interface and class definitions in Java:

interface A { void job1 (String x); }

interface B { void job1 (String x, String y); }

interface C { void job2 (String x); }

public class D implements A,B,C { ... }

List the methods (if any) that the class D is required to have given the declaration above. Give the

methods by their full signature (i.e., the method header); you are not required to give a body for any of the

methods. If D requires no methods, say so.

7.What are the roles of packages in Java? Why would we put two classes in the same package (ordifferent packages)?

What is the significance of public classes in a package.

Thanks!

Explanation / Answer

1. It can be relationshop between types and subtypes, type conversion or it is used to decide whether a method is overwritten or overloaded.

Ex. X and Y are types and F is type transformation (let's say it's a function which takes integer and returns boolean). and < is sub type.

3) Including header file in C++ : header file is included to get extra features / utility functions included in current CPP file. Header files can be included in two ways:

6) class D has to define all the functions of all the interfaces.

public class D implements A, B, C {

@Override

void job1(String x) {

// Implementation of the method

}

@Override

void job1(String x, String y) {

// Implementation of the method

}

@Override

void job2(String x) {

// Implementation of the method

}

}

7) Packages in java provide encapsulation (classes which are package-private -- default and protected classes are package private, can't be accessed outside the package). These are helpful in avoiding naming conflict for classes.
Public classes in a package can be accessed by the classes outside the package.