Friday, 14 September 2012

Java Practical - 4


    Program Definition 4 ::
   
     Define a class called Product, each product has a name, a product code and manufacturer name. Define variables, methods and constructors, for the Product class. Write a class called TestProduct, with the main method to test the methods and constructors of the Product class.




class Product
{
int productCode;
String name;
String manufacturerName;

Product()
{
System.out.println("\n Product Class Constructor Called ");
}
Product( int c, String nm, String mnm )
{
System.out.println("\n Product Class Constructor Called ");

productCode = c; name = nm; manufacturerName = mnm;
}

public String getName()
{
return name;
}
public int getProductCode()
{
return productCode;
}
}

class Prog4
{
public static void main(String arg[])
{
Product p = new Product(1,"Laptop","Lenovo");

System.out.println("Product Code :: " + p.getProductCode() );
System.out.println("Product Name :: " + p.getName() );
System.out.println("Product Manufacturer :: " + p.manufacturerName );
}
}

/*
D:\JAVA>java Prog4

 Product Class Constructor Called
Product Code :: 1
Product Name :: Laptop
Product Manufacturer :: Lenovo
*/


Kindly Bookmark and Share it:

0 comments :

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT