JAVA public class DataTypeClass { // A ? where A includes three following lines
ID: 3694259 • Letter: J
Question
JAVA
public class DataTypeClass
{
// A ? where A includes three following lines
private String str;
private static int intNum = 0;
private double doubleNum ;
// B ?
public DataTypeClass()
{
str = “unknown”;
doubleNum = 0.0;
}
// C ?
public DataTypeClass (String s, double d)
{
str = s;
doubleNum = d;
}
// D ?
public static void staticMethod ( )
{
intNum ++;
}
// E ?
public void setString (String s)
{
str = s;
}
// F ?
public int getIntNum()
{
return intNum;
}
// G ?
public String toString()
{
Return “String = “ + str + “ Integer Number = “ + intNum;
}
}
Question1:
Provide the name of the above session or methods
A.________
B.________
C._______
D._______
E._______
F._______
G._______
Question2:
Assume a program containing the driver class with the main method that declares two DataTypeClass objects as follows:
public class DriverClass
{
public static void main (String[ ] args )
{
DataTypeClass first = _________ ; // H: calling the no-argument constructor
DataTyepClass second = __________; // I: calling the parameter constructor to pass:
// “Jefferson Brown” and 3.5 to the object
System.out.println( first ); // J?
System.out.println( second ); // K?
// call the method staticMethod
____________________; // L ?
}
}
Write the complete lines H and I
Question3:
What is the output at the line J and K?
Question4:
Write the code on line L
Explanation / Answer
Question1:
A. str and doubleNum session is until the class object exists whereas intNum value will be persistent
B. default constructor
C. parametrised constructor
D. static methos to increment static variable intNum
E. setter for str variable
F. accessor for intNum
G overridden toString()
Question 2:
J: DataTypeClass first=new DataTypeClass();
K: DataTypeClass second=new DataTypeClass("Jefferson Brown",3.5);
Question 3:
J: String=unknown
Integer Number=0;
K: String=as
Integer Number=0;
Question 4:
L:
DataTypeClass.staticMethod(); or first.staticMethod() or second.staticMethod()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.