In: Computer Science
Question1 answer:
intVariable,floatVariable,stringVariables are instance variables of class DataTypeClass_Smith.
They hold the respective data(integer,float,string)for the class DataTypeClass_Smith.
Question 2 answer:
public DataTypeClass_Smith()
{
intVariable = 0; floatVariable = 0.0; stringVariable = “aString”;
}
DataTypeClass_Smith() is the default constructor of the class DataTypeClass_Smith and it initialise the instance variables with default values. When the object of type DataTypeClass_Smith is created with no parameters,then default constructor will be excuted and all the instance variables will be initialised with respective default values.
Question 3 answer:
public DataTypeClass_Smith( int intVar, float floatVar, String stringVar)
{
intVariable = intVar; floatVariable = floatVar; stringVariable = stringVar;
}
It is the parametrised constructor of the class DataTypeClass_Smith and it will initialise all the instance variables with values present in the constructor.
Ex: DataTypeClass_Smith obj = new DataTypeClass_Smith(1,2.5,”John”);
parametrised constructor is called and values will be set to respective instance variables.
Question 4 answer:
It is a setter method for intVariable and it will set the value to the instance variable intVariable.
Ex: obj.setIntVariable(45);
Question 5 answer:
It is a getter method for floatVariable and it will return value of floatVariable when it is called.
Question 6 answer:
This is a toString() method for the class DataTypeClass_Smith.
It will print or return string format or readable format of the object which had all the instance variables with values