Jump to content

Naming classes


Recommended Posts

Posted
9 minutes ago, obasan said:

What takes more memory?

void horn() {

System.out.println("BEEP");

}

OOORRRR

public static void() {

System.out.println("BEEP");}

 

------

 

Should you avoid using something like public static void when you can just get away with void???

Thanks!

Second one won't even compile, but source code != memory usage

Posted
40 minutes ago, obasan said:

What takes more memory?

void horn() {

System.out.println("BEEP");

}

OOORRRR

public static void() {

System.out.println("BEEP");}

 

------

 

Should you avoid using something like public static void when you can just get away with void???

Thanks!

Perhaps you should learn what public and static mean?

  • Like 1
Posted
11 hours ago, Explv said:

Perhaps you should learn what public and static mean?

public means that the class or object can be seen by others

static has something to do with instantiating or something.

12 hours ago, Token said:

Second one won't even compile, but source code != memory usage

fuk lol i forgot the add the horn() so its:

 

public static void horn() {

System.out.println("BEEP");

}

 

either way, what does use memory?

im guessing its all about calculations and variables you create...

i.e. dont use a double when u can get away with an int

i.e. find the most effective calculation method

Posted

Static is used when you want something to exist once.

For example:

Cat.purr(); // static - makes no sense. Cats purr individually.

Cat.count(); // static - makes sense. Get the count of all cats ever created.

new Cat().purr(); // not static - makes sense. Cats purr individually.

new Cat().count(); // not static - makes no sense. One cat can't account for all cats ever created.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...