Section 1

Preview this deck

What static means when applied to attribute or method?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

1

All-time users

1

Favorites

0

Last updated

1 year ago

Date created

Mar 1, 2020

Cards (13)

Section 1

(13 cards)

What static means when applied to attribute or method?

Front

It can be applied to a field, a method or an inner class. A static field, method or class has a single instance for the whole class that defines it, even if there is no instance of this class in the program. For instance, a Java entry point ( main() ) has to be static.

Back

Two methods every class should implement?

Front

o toString o equals- haven't done yet

Back

· Child x; int y; how do these differ?

Front

o Y- integer o X- address (reference variable) o X= new Child(); o Watch echo 360 o X stores the address of the object, the object is at the address x points too

Back

What is a Method?

Front

a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilizing the method's name. Think of a method as a subprogram that acts on data and often returns a value. Each method has its own name.

Back

What does import mean?

Front

o To bring in external packeges o Example- Import.java.util.scanner is a keyword. import keyword is used to import built-in and user-defined packages into your java source file so that your class can refer to a class that is in another package by directly using its name. Use the '*' character to declare all the classes belonging to the package.

Back

Why is main static?

Front

has to be declared static because keyword static allows main to be called without creating an object of the class in which the main method is defined. ... In this case, main must be declared as public , since it must be called by code outside of its class when the program is started. o Static doesn't mean constant or unchanging o Review echo 360 o In class why don't u see static anywhere o Static doesn't mean constant or unchanging o You are telling the compiler that this method or attribute exits without creating an object o So main has to be static because main is often in a file o Make it static so its not theoretical

Back

How is a rule passed?

Front

o Peremiters are passed by value o 2 ways to pass perimiters in java § Value § Reference o Perimiters are passed by default by value

Back

Difference between two class variable and instance variable

Front

Instance variables are declared in a class, but outside a method, constructor or any block. Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. Static(Class) variables and instance variables both are member variables because they are both associated with a specific class, but the difference between them is Class variables only have one copy that is shared by all the different objects of a class, whereas every object has it's own personal copy of an instance variable. So, instance variables across different objects can have different values whereas class variables across different objects can have only one value.

Back

What is a static method?

Front

belongs to the class and not its instances. ... Usually, static methods are utility methods that we want to expose to be used by other classes without the need of creating an instance. For example Collections class. Java Wrapper classes and utility classes contain a lot of static methods. Example: The most common example of a static method is main( ) method.As discussed above, Any static member can be accessed before any objects of its class are created, and without reference to any object. Methods declared as static have several restrictions: They can only directly call other static methods.

Back

Visibility Modifiers

Front

o Public- everyone can see it o Private- only things in that class can access it o Protected- parent class can access it outside can not

Back

What does extend do?

Front

o Makes the connection between a child and a parent means that you are creating a subclass of the base class you are extending. You can only extend one class in your child class, but you can implement as many interfaces as you would like.

Back

Why do we use inheritance?

Front

It allows us to build complex things by starting with a foundation and adding only what is usually needed is used when a class wants to use/inherit the features of another existing class. The class that wants to use the feature of another class, is called subclass, whereas the class whose features are to be used is referred to as superclass. Inheritance is used to use the existing features of a class.

Back

Example of class decleration

Front

§ Modifier Class <name> § { § Attributes § Methods § } § Make one up if you have to like parent or child · Public class example · { · Prtvate int age; · }

Back