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
Showing posts with label objects in java. Show all posts
Showing posts with label objects in java. Show all posts
Thursday, July 1, 2010
Thursday, June 24, 2010
Objects and Classes in Java
Objects - represent "things: from the real world.
the objects is made up of attributes and methods.
Attributes - define the object.
methods - describes the mechanism that actually perform its tasks.
Classes - describes a group or collection of objects with common properties and also define a type of objects
Example of classes:
- employee
- car
-chair
the objects is made up of attributes and methods.
Attributes - define the object.
methods - describes the mechanism that actually perform its tasks.
Classes - describes a group or collection of objects with common properties and also define a type of objects
Example of classes:
- employee
- car
-chair
Subscribe to:
Posts (Atom)