I will create a program using classes and objects. I Used two class name which are MainProgram and Message.
In class name MainProgram, the user will input thier name, and this input data will pass to class Message to print.
Program Code:
import java.io.*;
import java.util.Scanner;
public class MainProgram
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
String name="";
System.out.print("Enter your name:");
input=name.nextLine();
//calling the class
//create an object to call the method in class Message
Message x = new Message();
x.printing(name);
}
}
Class Program:
class Message
{
public void printing(String nm)
{
System.out.print("Your name is:" + nm);
}
}
If you run this program you go to the MainProgram . The mainProgram will process all class program.
Output:
Your name is: Jaypee
No comments:
Post a Comment