You are designing a class with several private instance vari

You are designing a class with several private instance variables, to allow the class user to update the variable values, what kind of method they should use? ANS: You are designing a class with several private instance variables to comply with the encapsulation OOP principle, to allow other class to access these variables, You would design special methods for read operations, what kind of methods are these? ANS (1). What should be the prefix for the method name? You would design special methods for read operations, what kind of methods are these? ANS (3). What should be the prefix for the method name? Study the separately distributed class source file: DEMO_Calc_BMI.java, then answer the following questions. In line 7, there is no public modifer (keyword). What would happen if put it back and compile the class? Explain briefly. We save the source as DEMO_CalC_BMI.java, why we do this way, instead of save it as Calc_BMI.java and run as Calc_BMI? If we delete line 6, what would happen when trying to compile? Can you execute class Calc_BMI without using a main to drive it? ANS: cycle: YES or NO

Solution

Note:

Could you please post the program in comment section.So that I may know what is the line 7 and line 6

______________________________

Answers:

8)

In order to update the instance variable we have to use setters methods or Mutator methods.By using these we have to modify the instance variable values.

9)

1)Accessor methods

2)get

3)Mutator methods

4)set

10)Answer)If we provide public class modifier.then jvm can able to locate the class.Then the class which is using that class could able to access it.so that we can compile and run the program.

11)

Class name and name of the java file should always be exactly same.

If we try to save the file name with different name other than the Class name we will get compilation error.

12)answer) if we delete the import statement that we cant able to compile our class..We will get compilation error during compiling the program

13)Answer) No

Reason:

We can able to run the class Calc_BMI with out the main() method.Because JVM starts the execution of the java program from the main() method.If we didnt declared the main() method with public access modifier .Then JVM couldnt able to identify the main() method.

___________________Thank You

 You are designing a class with several private instance variables, to allow the class user to update the variable values, what kind of method they should use?

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site