generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Does this forum do Java questions?

Previous Thread :: Next Thread 
jtrobloxian is not online. jtrobloxian
Joined: 10 Jul 2013
Total Posts: 2274
10 Jul 2016 07:12 PM
If so:
In the most easy to understand way possible, can you explain the difference between static and nonstatic variables?
Report Abuse
cntkillme1 is not online. cntkillme1
Joined: 16 Feb 2012
Total Posts: 592
10 Jul 2016 07:19 PM
It means only 1 exists, that is when you create a new class the static variables are not created. It's great for constants and for other variables you only need 1 of across all classes.
Report Abuse
Twister_1976 is not online. Twister_1976
Joined: 17 Sep 2010
Total Posts: 2494
10 Jul 2016 07:20 PM
I don't think it is. :l

But if I had to guess, static variables won't allow people to change it.
I don't do Java so..

If money grew on trees... It would be as valuable as leaves. | Twitter: @TwisterRBLX


Report Abuse
jtrobloxian is not online. jtrobloxian
Joined: 10 Jul 2013
Total Posts: 2274
10 Jul 2016 07:21 PM
That's a constant
Report Abuse
jtrobloxian is not online. jtrobloxian
Joined: 10 Jul 2013
Total Posts: 2274
10 Jul 2016 10:35 PM
package com.jtcode




class Bump {

public static void main(String[] args){

System.out.println("Bump.");
}
}
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
10 Jul 2016 10:41 PM
cntkillme already answered correctly.
Static classes can't be created or initialized.
Non-static classes can be created.

Sort of like on Roblox, Instance.new("Part") creates a new "Part" Instance. Static classes don't do that. Static classes are more like Tables in Lua.


Report Abuse
DoAnAileronRoll is not online. DoAnAileronRoll
Joined: 08 Feb 2015
Total Posts: 5360
10 Jul 2016 10:47 PM
"In the most easy to understand way possible, can you explain the difference between static and nonstatic variables?"




Static means that you access it by referring to the class - it is effectively 'permanent' in a sense that no derivative class "owns" it...

This is so that I can do this:

public class Animal
{
private static numOfAnimals = 0;
private String name;
public Animal()
{
this("animal");
}

public Animal(String name)
{
++numOfAnimals
this.name = name;
}

public static getNumOfAnimals()
{
return numOfAnimals;
}
}



Therefore, when we derive a class like this:

public class Wolf extends Animal
{
public Wolf() //No args constructor just to differentiate between Wolf and Animal.
{
super("a Wolf");
}

public Wolf(String name)
{
super(name);
}

public static void main(String[] args)
{
System.out.println(Animal.getNumOfAnimals()); //This will change depending on how many are made.
//Refer to it statically by referencing it's class.
}
}





Static variables are tied to classes, not objects. If that helps any.
Report Abuse
jtrobloxian is not online. jtrobloxian
Joined: 10 Jul 2013
Total Posts: 2274
10 Jul 2016 10:51 PM
So static variables enable you to access it in an class(Wolf) that inherits Animal?
Report Abuse
L2000 is not online. L2000
Joined: 03 Apr 2008
Total Posts: 77448
10 Jul 2016 10:53 PM
I'm assuming its already answered but yolo

Static variables are class variables, you access them from the class itself
Nonstatic are instance variables, like properties of the object and etc, you create a new one every time you create a new instance
Report Abuse
DoAnAileronRoll is not online. DoAnAileronRoll
Joined: 08 Feb 2015
Total Posts: 5360
10 Jul 2016 10:56 PM
No, they are tied to the Animal class.

When Wolf does something to a static variable in Animal, it affects Animal's static variable, not 'Wolf's', because Wolf does not inherit Animal's static variables.


This is so that I can call Animal's static variable, even after creating Wolf's, and any derivatives of Animal (in this example) are able to add to that counter 'numOfAnimals', without individually inheriting them. (Wolf doesn't have a 'numOfAnimals' field. Animal does.)

What the static modifier does is allow something to be independant of polymorphism and object-oriented structure, and behave a bit more like C and C-like non-OOP languages do. (Except not really, but it's a better analogy than before.)

Report Abuse
DoAnAileronRoll is not online. DoAnAileronRoll
Joined: 08 Feb 2015
Total Posts: 5360
10 Jul 2016 10:57 PM
This allows me to do something else as well:


public class Car
{
public void printOutNumOfAnimalsToWatchOutFor()
{
System.out.println(Animal.getNumOfAnimals()); //Doesn't have to be attached at all.
}
}

Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image