Answer:
The program to the given question can be given as:
Program:
import java.io.*; //import package for client class.
class Name //class-name Name.
{
// data members of the class.
String firstname, middleinitial, lastname;
// define parameterized constructor that would initialize data members
Name(String Fname,String Mname,String Lname)
{
this.firstname= Fname; //Using this key-word for holding value.
this.middleinitial= Mname;
this.lastname= Lname;
}
void showtime() //method showname with no return-type.
{
//define variable name for strore value.
String name;
name = firstname + " " + middleinitial + " " + lastname;
System.out.print(name); //print value.
}
}
class Main //main class
{
public static void main (String[] args) //main method.
{
Name ob =new Name("AAA","BBB","CCC");
//creating class object.and passing value to parameterized constructor.
ob.showtime();
//calling showtime function.
}
}
Output:
AAA BBB CCC.
Step-by-step explanation:
The explanation of the program can be given as:
In this program, we create a class i.e. (Name). In class, we declare a variable that's data type is String because It is a sequence of characters that hold a string value. Then we define the parameterized constructor. It is used for holding string values in it. We define a function i.e. showtime. This function is used for string value that is passed in the constructor. Then we create the main class that has the main method. It is used for calling the Name class by creating its object. After creating a name class object we pass the value to the parameterized constructor. and call the function, Where it is a function that doesn't have any return type.