ShmoopTube

Where Monty Python meets your 10th grade teacher.

Search Thousands of Shmoop Videos


AP Computer Science Videos 113 videos

AP Computer Science 1.2 GridWorld Case Study and APIs
493 Views

AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?

AP Computer Science 1.4 Standard Algorithms
200 Views

AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?

AP Computer Science 2.3 Classes and Objects
191 Views

AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?

See All

AP Computer Science 4.3 Classes and Objects 177 Views


Share It!


Description:

AP Computer Science 4.3 Classes and Objects. Which of the following should be declared as static?

Language:
English Language

Transcript

00:00

Hurry And here's your shmoop duties you're brought to you

00:06

by llamas that sound oddly like taylor swift a lot

00:12

Well you'd like to write a llama class to help

00:15

with keeping track of llamas on your farm This class

00:18

will include the following data members here Which of the

00:22

following should be declared as static ten come on And

00:28

here the potential answers numerals I came to enact a

00:32

llama All right here we go I'm nominating All right

00:38

We'll recall what the k word static means when you

00:41

declare something to be static You're telling the computer that

00:43

every instance of the object will hold the same value

00:46

for the variable that is static saying it doesn't change

00:49

like idiots in congress for example let's pretend our lama

00:53

class has another variable called for color Well now let's

00:57

say we create three instances of our lama class peanut

01:00

carl and dahlia if we made for color static and

01:04

then set it to grey while every lama created would

01:07

turn gray But if for color wasn't static then we

01:10

could change each llamas colored individual in a nutshell Static

01:15

variables are used to signify variables that should be the

01:17

same Across all instances of a class and non static

01:21

variables used for ones that should be unique among different

01:24

instances got it now let's Look at our answers We're

01:29

looking at three way want lama named to be static

01:32

Well that's like asking do we want everyone that i

01:34

have the same name Unless you want fifty llamas running

01:37

at you when you call carl probably should keep along

01:40

the name non static Now if we look at the

01:43

second answer the same problem occurs We can't make lama

01:46

idee static because that would make every lama be indistinguishable

01:51

by ideas like having same social security number for every

01:54

llama by process of elimination That leaves us with one

01:58

option left that's number one but let's double check that

02:01

it's right we want next available I'd be the same

02:06

across all instances of lama Well yeah this variable isn't

02:10

specific to just one lama in particular rather than lama

02:13

class a hole so should make it static Next time

02:17

i'll pack a bag so we can explore more about 00:02:20.68 --> [endTime] lama

Related Videos

AP Computer Science 1.2 GridWorld Case Study and APIs
493 Views

AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?

AP Computer Science 1.4 Standard Algorithms
200 Views

AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?

AP Computer Science 2.3 Classes and Objects
191 Views

AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism
204 Views

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...

AP Computer Science 4.2 Standard Algorithms
191 Views

AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?