Static Variable & Static Methods Flashcards

1
Q

1) Static Variables

When we declare a variable as being ‘static’ we have turned it into a ‘c_______ variable’.
This means that it can be used by all of the objects, and its value will be the same for all of the objects.

e.g. public class Dog

static int dogCount = 0 //This class variable could be used as a counter for every time a new Dog object
is made.

A

class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

2) Static Methods

Many of the methods we have seen so far have been ‘instance’ methods; i.e we create an instance (object) of the class and invoke its methods.

However, sometimes we want to use the services of a class (i.e. call a method), without having to create an o______.

e.g.
System.out.println(“….”) //We didn’t create an object to use this method!

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

3) Static Methods

Static methods are the methods in Java that can be called without creating an object of class.
They are referenced by the class n_____ itself or reference to the Object of that class.

public static void geek(String name)
{
// code to be executed….
}

// Must have static modifier in their declaration.
// Return type can be int, float, String or user-defined data type.

A

name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

4) Static Methods - Important Notes

Static methods are designed with the aim to be shared among all objects created from the same class.

Static methods can not be o________.

Static methods only have access to static variables.

Static methods can only call other methods in the class if they too are s______.

A

overridden
static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly