Starting from:
$16.99

$10.99

Questions and Answers

1. Does Encapsulation imply Data/Information Hiding in object-oriented programming? Why or why not? 

 

2. Keeping in mind all object-oriented programming best practices, create a class for a Chair, with the following specifications:

-. Specify two data members

-. Default Constructor

-. Overloaded Constructor which takes both data member values as input.

-. Generate a unique identification number for each object instantiated from this class. Use a static data member to keep track of the identification number last assigned to an object so that duplications will not occur. 

-. Show a statement which instantiates an object of this class using the overloaded constructor.

You do not need to provide any accessor/mutator methods or other methods.

 

3. Given the following list of classes, attributes and methods, 

- identify which items are classes, which items are attributes and which items are methods;

- identify which class each attribute and method belongs to; and

- suggest a class hierarchy given your list of classes.

*Note - no particular capitalization scheme is used in the list below to differentiate between classes, methods, and attributes.

AdhereToBuilding, NumberOfPetals, Photosynthesize, EmitFragrance, Length, Plant, Height, DaysToGermination, Rose, Grow, LosePetals, ConsumeWater, FloweringSeason, Vine, Color, LeavesPerInch


4. Briefly describe what an interface is and how it can be used in an object-oriented program. Provide example pseudocode showing how an s Interface might be constructed. 

 

5. How do you make an abstract method? When a class contains abstract method, what will happen? Can we still treat the class like a normal class? Provide pseudocode that represents an abstract class with at least one abstract method. (Points : 18)

 

6. Define and implement the overloaded constructors that support the following test function for a Rectangle class. The data members for the Rectangle class are length and width. Both are integer data types.

public static void main(String args[])

//r1 will take all default value
Rectangle r1 = Rectangle(); 

//r2 will take all supplied value
Rectangle r2 = Rectangle(4, 5); 

//r3 will take supplied length. width will take default value
Rectangle r3 = Rectangle(10); 

//r4 will take the same value of r2
Rectangle r4= r2; 

//the rest of the code
}


7. 

Create a Java Interface called Auto that contains two method declarations: moveForward and turnRight. Create a Java class called FordTruck that implements the Auto interface and includes two attributes: model and yearBuilt. Finally, show an instantiation of the FordTruck class that sets the FordTruck's model to F550 and yearBuilt to 2002. (Points : 22) 

 

More products