First Class
![]() |
![]() Mrs Ws 1st Grade Class Fashion Princess Perfect $29.99 Time Remaining: 3h 54m |
![]() Evelt Trikeri Costume doll Greece free first class mail $12.95 Time Remaining: 12d 36m Buy It Now for only: $12.95 |
![]() GROOVE INC VOCALOID HATSUNE MIKU LOL Ver 1st Class International Shipping $130.50 Time Remaining: 13d 22h Buy It Now for only: $130.50 |
![]() Monsieur Z First Class Pilot Jason Wu doll Integrity Toys $79.90 Time Remaining: 22d 19h 8m Buy It Now for only: $79.90 |
![]() NUDE MONSIEUR Z FIRST CLASS FLIGHT ATTENDANT Blonde 4 repaint $35.00 Time Remaining: 5d 22h 10m Buy It Now for only: $35.00 |
![]() Cherished Teddies Tony A First Class Delivery For You Mail Car Figurine $11.99 Time Remaining: 21d 22h 18m Buy It Now for only: $11.99 |
![]() SAWYER Habitat for Humanity Bear Limited Edition NEW free first class mail $13.95 Time Remaining: 20d 23h 3m Buy It Now for only: $13.95 |
![]() Dan Dee 1st Class Graduate Teddy Bear w picture frame 2002 $15.99 Time Remaining: 15h 46m Buy It Now for only: $15.99 |
![]() Annalee Mobilitee Doll First Class Mail Mouse with Mailbox 6 $15.95 Time Remaining: 10d 22h 17m Buy It Now for only: $15.95 |
![]() Titanic Jaynee 1st Class Maid Doll 100th Anniversary Edition $7.99 Time Remaining: 21h 19m |
![]() First Class Monsieur Z Flight Attendant Stewardess Doll Jason Wu 2005 Mint NRFB $84.99 Time Remaining: 26d 16h 54m Buy It Now for only: $84.99 |
![]() Boyds PIN Miss Wise First Class Teacher FREE SHIPPING $8.50 Time Remaining: 29d 23h 24m Buy It Now for only: $8.50 |
![]() JUN PLANNING GROOVE INC DAL HELLO LITTLE GIRL 1st Class International Shipping $117.00 Time Remaining: 13d 18h 33m Buy It Now for only: $117.00 |
![]() PRECIOUS DREAMS LEVEL 1 OOAK POLYMER CLAY SCULPTING COURSE LEARN BABY DOLL ART $274.44 Time Remaining: 4d 6h 47m Buy It Now for only: $274.44 |
![]() Barbie as Daphne Scooby Doo Doll 2001 NEW NIB 55887 FREE 1ST CLASS SHIPPING $37.95 Time Remaining: 27d 19h 29m Buy It Now for only: $37.95 |
![]() MONSIEUR Z FIRST CLASS JASON WU FLIGHT ATTENDANT PAN AM $59.00 Time Remaining: 29d 16h 20m Buy It Now for only: $59.00 |
![]() GROOVE INC PULLIP SAN DIEGO COMIC CON LIMITED EDITION CATWOMAN 1st Class $126.00 Time Remaining: 13d 22h 2m Buy It Now for only: $126.00 |
![]() First Class Fashion for 14 Inch Betsy and Friends $39.99 Time Remaining: 3d 3h 54m |
![]() JUN PLANNING PULLIP DAL Kotoya 1st Class International Shipping $88.99 Time Remaining: 13d 21h 50m Buy It Now for only: $88.99 |
![]() Kimmidoll iPhone 4 4s Cover Eika Successful Free 1st Class PP $15.67 Time Remaining: 20d 19h 25m Buy It Now for only: $15.67 |
![]() Pink Breast Cancer Bean Filled Bear First Class Stamp $3.50 Time Remaining: 9d 17h Buy It Now for only: $3.50 |
![]() 1994 Happy Holidays Gala Barbie NRFB retailed 7599 free 1st class shipping $35.00 Time Remaining: 27d 19h 1m Buy It Now for only: $35.00 |
![]() Uptown Chic 1994 Barbie Doll NIB LEATHER AND LACE FREE 1ST CLASS SHIPPING $35.00 Time Remaining: 27d 20h 48m Buy It Now for only: $35.00 |
![]() JASON WU FIRST CLASS STEWARDESS BARBIE DOLL MUSE MODEL NEW NRFB BLONDE $79.99 Time Remaining: 29d 15h 23m Buy It Now for only: $79.99 |
![]() Kimmidoll iPhone 4 4s Cover Nami Good Luck Free 1st Class PP $15.67 Time Remaining: 15d 16h 33m Buy It Now for only: $15.67 |
First Class

Concepts Involved With Classes In Java
Concepts Invoved with Classes
Any thing in java revolves around a class,Any concept we wish to implement in java program must be encapsulated with in a class .
- Ø class and object
Class is used to define new data type, once defined this new type can be used to create objects.
Thus a class is a template for an object and an object is an instance of a class.
- Ø General form of a class:
A class is declared by use of the class keyword.
class
{
type InstanceVariable1;
type InstanceVariable2;
type InstanceVariable3;
//
type InstanceVariableN;
type MethodName1(ParameterList)
{
//body of method
}
type MethodName2(ParameterList)
{
//body of method
}
//
type MethodNameN(ParameterList)
{
//body of method
}
}
The data variables, defined with in a class are called instance variables. Code is contained in methods.
Collectively, the methods and variables are called members of the class.
- Ø A Simple Class
class Box
{
double width;
double length;
double height;
}
a class declaration only creates a template.
To create a Box object. This statement is used is
Box MyBox = new Box(); // creates Box object called MyBox
- Ø dot operator
The methods and the instance variables associated with an object can be accessed with the dot operator.
For example to assign values to width, length and height variables with in MyBox object.
MyBox.width = 100;
MyBox.length = 100;
MyBox.height = 100;
- Ø new operator
The new operator dynamically allocates memory for an object and returns reference to it. i.e; a new object is created with the operator new. For example
Box MyBox = new Box ();
1) Lets examine a program that uses the Box class
/* A simple program demonstrating the ability to use classes */
class Box
{
double width;
double height;
double length;
}
class BoxDemo
{
public static void main(String args[])
{
Box MyBox;
MyBox = new Box();
MyBox.width = 23.33;
MyBox.height = 33.33;
MyBox.length = 43.33;
System.out.println("length of MyBox object is "+ MyBox.length);
System.out.println("hight of MyBox object is "+MyBox.height);
System.out.println("width of MyBox object is "+MyBox.width);
}
}
2) Lets re write the above program with a slight difference
/* This program BoxDemo1.java calculates the volume of each box object*/
class Box
{
double length;
double width;
double height;
}
class BoxDemo1
{
public static void main(String args[])
{
Box MyBox1 = new Box ();
Box MyBox2 = new Box ();
Box MyBox3 = new Box ();
double vol1,vol2,vol3;
//initializing objects MyBox1's variables
MyBox1.width =23.33;
MyBox1.height = 33.33;
MyBox1.length =43.33;
//initializing objects MyBox2's variables
MyBox2.width =33.33;
MyBox2.height = 43.33;
MyBox2.length =53.33;
//initializing objects MyBox3's variables
MyBox3.width =43.33;
MyBox3.height = 53.33;
MyBox3.length =63.33;
//calculating MyBox1 volume
Vol1 = (MyBox1.width*MyBox1.height*MyBox1.length);
//calculating MyBox1 volume
Vol2 = (MyBox2.width*MyBox2.height*MyBox2.length);
//calculating MyBox1 volume
Vol3 = (MyBox3.width*MyBox3.height*MyBox3.length);
//displaying the volume of MyBox1
System.out.println ("volume of MyBox1 is "+vol1);
//displaying the volume of MyBox2
System.out.println ("volume of MyBox2 is "+vol2);
//displaying the volume of MyBox3
System.out.println ("volume of MyBox3 is "+vol3);
}
}
- Ø Declaring Objects
Obtaining objects of a class is a two-step process
- · First, You must declare a variable of the class type. This variable does not define an object, it is simply just a variable that can refer to an object. For example to declare a variable of Box class use the following syntax.
Box My Box; // My Box is just a variable of type Box, My Box contains NULL value.
- · Second, You must acquire an actual, physical copy of the object and assign it to that variable. You can do this using the new operator. The new operator dynamically allocates memory for an object. The following code best illustrates this
MyBox = new Box() ; // allocate a Box object.
Note object can also be created using the below statement
Box MyBox = new Box();
- Ø Assigning object reference variable
When we assign one object reference variable to another object reference variable, we don't create
a copy of the object, but we only make a copy of the reference.
consider the example below
Box MyBox1 = new Box();
Box MyBox2 = MyBox1;
Here MyBox1 and MyBox2 refer to the same object. as shown in the below picture
Width
Height
Depth
MyBox1
MyBox2
Box Object
So any changes made in width, height and depth in MyBox2, will be reflected in MyBox1 object also.
- Ø Methods
If we observe the above program 1.3.4, we find that the instance variables are being accessed directly by the object MyBox1, MyBox2, MyBox3 which is not a favored situation in oops. As one of the oops principle, data abstraction and encapsulation is not implemented.Thus best way to achieve data abstraction and encapsulation is through methods.
3)// the program includes a method setValues() and another method volume()
class Box
{
double width;
double length;
double height;
void setValues(double width,double length,double height)
{
this.width = width;
this.length = length;
this.height = height;
}
void volume()
{
System.out.println();
System.out.println("the volume of the box is : "+ (width*height*length));
}
}
class BoxDemo3
{
public static void main(String args[])
{
Box MyBox1 = new Box();
MyBox1.setValues(10,20,30);
MyBox1.volume();
}
}
You will observe that while assigning values to variables of class or while calculating volumes of each box, the objects are not allowed to access the data directly. (data abstraction and encapsulation)
Now consider if we wanted to calculate the cost of a box, depending on its volume. Observe the above program, the volume() method, just simply displays volume of a box on the screen, if we want to calculate the cost of the box, then volume calculated by the volume() method should be multiplied with the cost , that means the volume() method should return a value, let us see how this is achieved.
4) // this program introduces a method volume() that returns a value and this value is used to calculate the cost of the box.
class Box
{
double width,length,height,cost;
void setValue(double width,double length,double height,double cost)
{
this.width = width;
this.length = length;
this.height = height;
this.cost = cost;
}
double volume()
{
return length * height * width;
}
void cost()
{
System.out.println( "Cost of the box is "+cost * volume() );
}
}
class BoxDemo4
{
public static void main(String args[])
{
Box MyBox1 = new Box();
Box MyBox2 = new Box();
MyBox1.setValue(10,20,30,4.5);
MyBox2.setValue(30,40,50,5.5);
MyBox1.cost();
MyBox2.cost();
}
}
In the above two examples, we have seen two types of methods: method that takes parameters,setValue() and
method with out parameters, volume().
- Ø Constructor
We know that ,when an object is created, it's variables have to be initialized, Instead of initializing the class instance variables, after an instance is created, with convenient functions like setValues(), as in the previous example. It could be more convenient to have the initialization done, at the time the object is first created. Fortunately, java allows objects to initialize themselves when they are created. This automatic initialization is performed through the use of a constructor.
i. A constructor initializes an object immediately upon creation.
ii. A constructor has the same name as the class in which it resides and is syntactically similar to a method.
iii. Constructors don't have return type not even void, this is because the implicit return type is class type itself.
Default constructor:
Lets us take a closer look at the new operator in the below statement
class_var = new class_name();
Now you can understand why the parenthesis are needed after the class_name().
What is actually happening is that the constructor for the class is being called.
This is in the line Box MyBox1 = new Box ();
new Box () is actually is calling a default constructor.Java creates a default constructor, because the constructor is not defined in the class,
The default constructor automatically initializes all instance variables to zero.
Parameterized Constructor's:
The default constructor discussed above, is of no use, though it initializes the instance variables of Box to zero because a box will have dimensions other than zero. So to construct Box objects of various dimensions, the easy solution is to add parameters to the constructor. As shown in the example below
5) /* In this program, here Box uses a parameterized constructor which sets the dimensions of a box as Specified by those parameters */
class Box{
double length,height,width;
Box(double length,double height,double width )
{
this.length = length;
this.height = height;
this.width = width;
}
double volume( ){
return length * height * width;
}
}
class BoxDemo5{
public static void main(String args[]){
Box MyBox1 = new Box(10,20,30);
Box MyBox2 = new Box(40,50,60);
double vol;
vol = MyBox1.volume();
System.out.println("volume of MyBox1 is "+ MyBox1.volume());
System.out.println("volume of MyBox2 is "+ MyBox2.volume());
}
}
- Ø This Key Word
Sometimes a method will need to refer to the object that invoked it. Java defines the "this" key
Word, for this purpose. "This"key word can be used inside any method to refer to the current
Object.
6) //this program demonstrates the ability and usage of this key word
class Box
{
double width;
double height;
double depth;
double cost;
Box (double width, double height, double depth,double cost)
{
this.width = width ;
this.height = height;
this.depth = depth;
this.cost = cost;
}
double volume(){
return width*height*depth;
}
double cost()
{
return this.volume()*cost;
}
}
class BoxDemo6
{
public static void main (String args[])
{
Box MyBox1 = new Box (23.33,33.33,43.33,5.5);
Box MyBox2 = new Box (20,30,40,5);
System.out.println("cost of MyBox1 "+MyBox1.cost());
System.out.println("cost of MyBox2 "+MyBox2.cost());
}
}
- Ø Instance Variable Hiding
It is illegal to declare two variables with the same name, with in the same scope but Interestingly, you can have local variables, including formal parameters to methods, which overlap with the names of the class's instance variable.
However when the local variable has the same name as the instance variable, it hides the instance variable. This was the reason, name's width, height & depth were not used as the names of the parameters' to the Box() Constructor. if they had been then width, height and depth would have referred to the formal parameter's, there by hiding the instance variable's (width, height and depth).
To handle such a situation considers the program below.
/* Technique to resolve when local variables' names'
are same as names' of instance variables of class */
/* A simple program demonstrating the ability to use classes */
class Box
{
double width;
double height;
double length;
Box(double length,double width,double height)
{
this.width = width;
this.height = height;
this.length = length;
}
}
class BoxDemo8
{
public static void main(String args[])
{
Box MyBox = new Box(23.33,33.33,43.33);
System.out.println("length of MyBox object is "+ MyBox.length);
System.out.println("length of MyBox object is "+MyBox.height);
System.out.println("length of MyBox object is "+MyBox.width);
}
}
- Ø Garbage Collection
An object is assumed to be no longer needed, when no references exist to an object, hence such objects have to be destroyed, so that the memory is reclaimed. In java, there is no explicit need to destroy objects as in c++.
Garbage collector will act, automatically, when ever one or more unused objects exist.
Java run time environment will decide when the garbage collection be done. However, we can only request the java run time environment to invoke the garbage collector. Again it is at the decision of Java run time environment, to decide when to invoke the garbage collector. We can invoke by calling, static method gc() of System class.
Lets us understand it by an example shown below
//this program demonstrates the ability and usage of this key word
class Box
{
double width;
double height;
double depth;
double cost;
Box (double width, double height, double depth,double cost)
{
this.width = width ;
this.height = height;
this.depth = depth;
this.cost = cost;
}
double volume(){
return width*height*depth;
}
double cost()
{
return this.volume()*cost;
}
}
class BoxDemo7
{
public static void main (String args[])
{
System.gc();
Box MyBox1 = new Box (23.33,33.33,43.33,5.5);
Box MyBox2 = new Box (20,30,40,5);
System.gc();
System.out.println("cost of MyBox1 "+MyBox1.cost());
System.out.println("cost of MyBox2 "+MyBox2.cost());
System.gc();
}
}
- Ø Finalization
By using finalization mechanism, we can define specific actions that should occur, when an object is just about to be destroyed, by the garbage collector.
an object will need to perform some action when it is destroyed.
finalize() method
Some times, an object might be holding non java resource, such as a file handle or window character font. So the object needs to free these resources, before it is destroyed. Java provides a mechanism called finalization, So the object performs some action before it is finally destroyed.
To achieve finalization, we simply define the finalize() method, in the class.Inside the finalize() we will specify those actions that must be performed before the object of that class ,is destroyed.
The general form is
protected void finalize()
{
// finalization code here
}
here, the key word protected is a specified that prevents access to finalize() method, defined outside its class.
About the Author
the author is trainer and developer in oracle and java technolgies. you can reach me on raju.allu@yahoo.com
X-Men: First Class Movie Trailer Official (HD)

























