2 Replies - 203 Views - Last Post: 16 November 2009 - 11:00 AM Rate Topic: -----

#1 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

General java question

Posted 16 November 2009 - 10:54 AM

I wanted to know what this is

is it creating a new instance of h1 ? iv seen some coding like this before is it like calling a class within main method?

[code]
public static void main(String[] args) {
new h1();
}



}

[/code}
Is This A Good Question/Topic? 0
  • +

Replies To: General java question

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: General java question

Posted 16 November 2009 - 10:57 AM

Yes. It creates a new h1 object. I imagine all the work it does is in the constructor because you don't have a handle for it.
Was This Post Helpful? 0
  • +
  • -

#3 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1940
  • View blog
  • Posts: 4,027
  • Joined: 11-December 07

Re: General java question

Posted 16 November 2009 - 11:00 AM

Exactly. It creates a new instance of h1.

Usually you would assign it to a variable so you can do something with it.
h1 my_h1 = new h1();

but sometimes the constructor is enough to kick off the program. A common use of what you posted is if h1 extends JFrame the constructor can call setVisible(true). This means that new h1() will both create and display the window.

I'm not a fan of doing that but it's common enough. :)

aaaah. Ninjaed by the new mentor. ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1