Answer:
The program to this question can be given as:
Program:
class Name //define class
{
//define variable.
String firstName="XXX";
String lastName="YYY";
char[] middleInitial;
}
public class Main //define main class.
{
public static void main(String a[]) //define main method
{
Name ob = new Name(); //creating name class object.
String FirstName = ob.firstName;
String LastName = ob.lastName; //calling
char[] MiddleInitial = ob.middleInitial;
System.out.println("First name "+FirstName); //print values.
System.out.println("Middle name "+MiddleInitial);
System.out.println("Last name "+LastName);
}
}
Output:
First name XXX
Middle name null
Last name YYY
Explanation:
In the above program firstly we define class Name that is given in the question. In this class, we define a variable that's datatype is string because it stores the string values. In this variable, we assign the value in the first and last name variables. In the middle name, we do not assign any value so it will print null. In the last we define the main class in this class we define the main method. In this method, we create a name class object and call the variable and print its value.