T0 Study the separately distributed class source file DEMO C
Solution
Question 10.10
It will show an error message as follows:
class Calc_BMI is public, should be declared in a file named Calc_BMI.java
 public class Calc_BMI //7
Because the the file name is DEMO_Calc_BMI which contains the main function and the class which contains the main method must be the file name which is must be public. In our program we made the Calc_BMI as public so it is asking the file name should be Calc_BMI.java.
Question 10.11
We are saving the file with DEMO_Calc_BMI.java becuase this class contains the main method. Every program starts its execution from main method and it is static because it doesnot need object to run. so while executing we are using: java DEMO_Calc_BMI.
We dont have main method inside the Calc_BMI class. If we well save the file with Calc_BMI.java then we need to make it public and we need run it as follows:
java Calc_BMI
Question 10.12
If we will delete line number 6 then it show an error message as follows:
cannot find symbol JOptionPane.showMessageDialog(null, \"O/P format - \" + fmt //34
Because while refereing JOptionPane.showMessageDialog() method it will look for the class swing.JOptionPane and it is not included in our program.
Question 10.13
Yes
If we well save the file with Calc_BMI.java then we need to make it public and we need run it as follows:
java Calc_BMI
Question 10.14
These are all Parameterized constructors.
Question 10.15
It will not generate syntax error because it will treat this as a method not as constructor because it contains return type as void. Constructor does not have return type not even void.
Question 10.16
These methods are used to change/set the value of the class data member.
These methods are called Impure functions or Mutator methods.
The methods that change the state of their object are called Impure functions or Mutator methods.
Question 10.17
These methods are used to return values to the caller about the state of an object.
These methods are called Pure functions or Accessor Methods.
Question 10.18
No.
These are simple methods. Method names can be any valid identifier.
Question 10.19
No.
double is return type for the method BMI().
Question 10.20
While calling a constructor it matches the parameter and the constructor which matches the number and type of parameter matching it will call the constructor.
In our example: Calc_BMI(\"John Goodman\", 170, 69)
It passes 3 parameters one string and two integer type and it matches with the following constructor:
public Calc_BMI (String newName, int newW, int newH)   //16
    {   name = newName;   w = newW;   h = newH;}   //17
Question 10.21
Yes
this is uses for current reference. In our program we can ommit this.
Question 10.22
b.writeOut(); //45
The above function will call the follwoing method:
public void writeOut()//28
    {System.out.print(\"Name: \" + name + \", Weight = \" + w //29
        + \", Height = \" + h + \", BMI = \" + BMI());}//30
Because it does not takes any parameter.
b.writeOut(\"GUI\"); //46
The above method will call the following method:
public void writeOut(String fmt)//33
    {
        JOptionPane.showMessageDialog(null, \"O/P format - \" + fmt //34
            + \"\  Name: \" + name + \"\  Weight = \" + w //35
        + \"\  Weight = \" + h + \"\  BMI = \" + (int) BMI() ); //36
    }
Because it takes \"GUI\" a string type parameter


