Thursday, June 24, 2010

Creating an object in java program

Creating an object in java program 
class Puppy{
   public Puppy(String name){
      // This constructor has one parameter, name.
      System.out.println("Your Name is :" + name ); 
   }
public static void main(String []args){
      // Following statement would create an object myPuppy
      Puppy myPuppy = new Puppy( "Jaypee" );
   }
}
sample output:
Your Name is : Jaypee

Creating an Object in Java

Creating an Object:

As mentioned previously a class provides the blueprints for objects. So basically an object is created from a class. In java the new key word is used to create new objects.
There are three steps when creating an object from a class:
  • Declaration . A variable declaration with a variable name with an object type.
  • Instantiation . The 'new' key word is used to create the object.
  • Initialization . The 'new' keyword is followed by a call o a constructor. This call initializes the new object.

java tutorial

http://www.tutorialspoint.com/java/index.htm

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

Flowcharting Problem and Solution

This is a sample flowchart and algorithm solution to the problem compute two numbers and get the sum.
this a good steps to solve the problem in programming.

Flowchart problem #1

Problem # 1: Create a flowchart and algorithm that compute two numbers and get the sum.

i will post the solution of this problem tommorow.