• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

object creation in java

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ???
 
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);



}
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic