aspose file tools*
The moose likes Beginning Java and the fly likes object creation in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object creation in java" Watch "object creation in java" New topic
Author

object creation in java

Aashish Jd
Greenhorn

Joined: Oct 14, 2012
Posts: 4
i am beginner in java and had little confusion with these object creation.I was making this code for assigning object to other object
here is the code

i like to know how the gb and gb1 object can be declared inside its own class ???

class Obj {
float b;
public static void main(String[] args){

Obj gb=new Obj();
Obj gb1=new Obj();
gb.b=3;
gb1.b=4;

System.out.println("first--->"+gb.b+"\n Second"+gb1.b);

}

}

i like to know how the gb and gb1 object can be declared inside its own class ???
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

Welcome to JavaRanch!

Aashish Jd wrote:i like to know how the gb and gb1 object can be declared inside its own class ???

Yes you can. Did you try compiling the code?


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Aashish Jd
Greenhorn

Joined: Oct 14, 2012
Posts: 4
yes the code works fine
but i wanna know how and where object can be created for a particular class???
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

You have already created two objects with the references gb and gb1. Are you asking where else such objects can be created?
Aashish Jd
Greenhorn

Joined: Oct 14, 2012
Posts: 4
i think i m not making my question understandable to you the thing is
before completely creating the class how can its object(gb and gb1 in this case) be created inside it
or in other sense how is it possible that the object of a class can be created inside its own class
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7063
    
  16

Aashish Jd wrote:or in other sense how is it possible that the object of a class can be created inside its own class

Because the class is the definition, the object is...well...an object.

I can describe a car to you; even show you a photograph or blueprints for it; without having to have an actual car. The object is the car; the class is the design document for the engineer (or, in Java's case, the JVM) that builds a car.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
amr talaat
Greenhorn

Joined: Sep 02, 2012
Posts: 19
Aashish Jd wrote:i think i m not making my question understandable to you the thing is
before completely creating the class how can its object(gb and gb1 in this case) be created inside it
or in other sense how is it possible that the object of a class can be created inside its own class



do you mean constuctors ???

class obj{

float f ;

public obj(float f)
{
this.f=f;




}

public void main (String args[])

{
Obj gb=new Obj(3);
Obj gb1=new Obj(4);

System.out.println("first--->"+gb.b+"\n Second"+gb1.b);



}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: object creation in java
 
Similar Threads
Can anybody Explain the Program
Another Garbage Collector question
Garbage Collection Program
Garbage Collection question
Garbage Collection question