Give example of encapsulation and inheritance relationship

Assignment Help Computer Engineering
Reference no: EM133591918

Assignment

For problems I through IV, explain why the code as shown is almost certainly not what the programmer intended, and how it should be fixed to work the way the programmer probably had in mind.

Question I. What is wrong with the following program and how should it be fixed?

1 public class MyClassA {
2 int v = 12;
3
4 public MyClassA (int pV) {
5 v = pV;
6 }
7
8 public static void main (String args []) {
9 MyClassA m = new MyClassA ();
10 } // end main
11 } // end class MyClassA

Question II. What is wrong with the following program and how should it be fixed?

1 public class MyClassB {
2 int v = 12;
3
4 public void MyClassB (int pV) {
5 v = pV;
6 }
7
8 public static void main (String args []) {
9 MyClassB m = new MyClassB (23);
10 } // end main
11 } // end class MyClassB

Question III. What is wrong with the following program and how should it be fixed?

1 public class MyClassD {
2 public static void main (String args []) {
3 MyClassC m = new MyClassC (23);
4 } // end main
5 } // end class MyClassD
6
7 class MyClassC {
8 int v = 12;
9
10 public MyClassC (int pV) {
11 int v = pV;
12 } 2
13
14 } // end class MyClassC

Question IV. What is wrong with the following program and how should it be fixed?

1 public class MyClassE {
2 public static void main (String args []) {
3 MyClassF m = new MyClassF (23);
4 } // end main
5 } // end class MyClassE
6
7 class MyClassF {
8 int v = 12;
9
10 private MyClassF (int pV) {
11 v = pV;
12 }
13
14 } // end class MyClassF

Question V. Given all the problems identified in problems 1 through 4, explain in detail why the following code works, ie, compiles without errors or warnings.

1 public class MyClassG {
2 public static void main (String args []) {
3 MyClassH m = new MyClassH (23, true);
4 } // end main
5 } // end class MyClassG
6
7 class MyClassH {
8 int v = 12;
9
10 public MyClassH (int x, boolean b) {
11 this (x);
12 }
13
14 private MyClassH (int pV) {
15 v = pV;
16 }
17
18 } // end class MyClassH

Question VI. Explain why the following class hierarchy is not reasonable:

DefenseDepartment

1. General
a. Private 3

Question VII. Give at least one example of a reasonable field for each of the following classes in the following class hierarchy. Be sure that the field is at the right level in the hierarchy.

Vehicle

1. Car

2. Airplane

a. Passenger
b. Fighter
c. Bomber

3. SpaceShip

Question VIII. Give at least one example of a reasonable method for each of the following classes in the following class hierarchy. Be sure that the method is at the right level in the hierarchy. Constructors, getters and setters don't count for this problem.

Vehicle

1. Car

2. Airplane

a. Passenger
b. Fighter
c. Bomber

3. SpaceShip

Question IX. Provide an example of an encapsulation and an inheritance relationship? Explain

Question X. Present reasonable parent and child classes for the class Tree (the biological kind). Give a short explanation for why the classes you are proposing are in good parent-child relationships.

Reference no: EM133591918

Questions Cloud

Why it is a critical component of starting a business : explain what the validation stage is and why it is a critical component of starting a business. Make sure you provide a strong justification for
What is your strategy to address this quickly : What is your strategy to address this quickly so you can resolve the crisis and not get stuck in a cycle of analytical paralysis?
Record legal concerns in regards to search and seizure : In your investigative journal, record legal concerns in regards to search and seizure, expectation of privacy, and collecting and handling evidence.
Explains the principal and agent relationship in mortgage : which explains the principal and agent relationship in mortgage broking or finance. Select all that apply A principal is a person who introduces parties
Give example of encapsulation and inheritance relationship : Provide an example of an encapsulation and an inheritance relationship? Present reasonable parent and child classes for the class Tree (the biological kind).
How might an hr professional avoid data misrepresentation : How might an HR professional avoid data misrepresentation to his or her strategic partners? provide references. Be sure to support your work with specific
Describe what you would do to change the company policy : Using what you have learned in this chapter, describe what you would do to change the company's policy toward employing illegal workers.
Creating a marketing plan for a product or service : HI5004 Marketing Management, Holmes Institute - Creating a marketing plan for a product or service. This project is designed to accomplish such a task
Construct a website of your choice utilizing newly learn : Construct a website of your choice utilizing newly learned skills. Note: You must build original website and website must have a minimum of three website pages.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd