• Post Reply Bookmark Topic Watch Topic
  • New Topic

guys, please help me understand the code :)  RSS feed

 
Dana Horst
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there! i am very new to java and have the Q about following code:

public static void main(String[] args) {
BasisFrame whatever = new BasisFrame();}

ok, i declare a new variable "whatever" type "BasisFrame". in a meanwhile i assign a new object(my tutorial says so). I dont understand where is my new object.

does following code means the same? :

public static void main(String[] args) {
BasisFrame whatever; //new variable whatever type basisframe
whatever = new BasisFrame() // new object whatever

thanks!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Dana.

In the first example you're declaring a variable and initializing it immediately by making it refer to a new BasisFrame object.

In the second example you're doing exactly the same, except that you're declaring the variable and assigning it to a new BasisFrame object on two separate lines.

The two do essentially exactly the same thing. In both cases, the variable whatever refers to the BasisFrame object.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this is the same.
 
Dana Horst
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jesper!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!