Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object creation in java

 
Aashish Jd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 4433
256
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Aashish Jd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes the code works fine
but i wanna know how and where object can be created for a particular class???
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4433
256
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
amr talaat
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);



}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic