Java static methods and variables

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the syntax of a static method?

<class-name>.<method-name>

can you use a non static variable int a static method

No only a static variable.

example of a calling a static method

System.arraycopy();

One rule of thumb when creating objects

ask yourself "does it make sense to call this method, even if no Obj has been constructed yet?" If so, it should definitely be static.

What is a static method?

is a method which belongs to the class and not to the object. A static method can access only static data.

How can I make the public void show() method static public class StaticDemo{ public static void main(String[] args){ } class abc{ public void show(){ system.out.print("Hi"); } }

public class StaticDemo{ public static void main(String[] args){ } class abc{ public static void show(){ system.out.print("Hi"); } }

How do you declare a static variable?

static int = 5;

when might you want to create a static method?

when you want to call a method without creating the object


Ensembles d'études connexes

Ch 9. Prenatal Influences on Development

View Set

Real Estate License Exam Review 2

View Set

IT Fundamentals Pro, Chapter 8: Programming - Vocabulary

View Set

Module 8 Quiz: Blood, Lymphatic System, and Immunity

View Set

Chapter 15 - Anxiety and Obsessive-Compulsive Related Disorders

View Set

PRNU 132 Pediatric Study Questions

View Set