• Mauvais document ? Échangez-le gratuitement
  • Rédigé par des étudiants ayant réussi
  • Disponible immédiatement après paiement
  • Lire en ligne ou en PDF
Vendre
Où étudie-tu ?
La langue
Document preview thumbnail
Aperçu 2 sur 6 pages
Resume

Summary Character and strings sum

Document preview thumbnail
Aperçu 2 sur 6 pages

Making Java easier for IEB students

Aperçu du contenu

ddStatic vs Non-static Methods:


What is a Non-Static Method?
• A non-static method is a method that we say “belongs to
the object”
• When you instantiate (create) a new object, a chunk of RAM
gets reserved and copies of all the parent methods (and
fields) are written into that space.
• Each object has inherited its own set of methods (this is one
of the foundations of OOP)
• The Gogga object has its own copy of move(), setDirection(),
etc
• ALL of these inherited methods are non-static methods
• You call a non-static method by using the object name
(Gogga bob = new Gogga();
bob.setPosition(5,7);)
What is a Static Method?
• A method that is “global” it is common to all objects.
• Not every object can inherit its own copy of such a method.
• Single instance of this method is held instead by the class
• Static method “belongs” to the class
• ALL the Gogga object that we create sit on the same grid
• setGridSize() method is static because ALL Goggas use the
same Grid
• You call static methods by calling their class name and also
the String class (char upperChar =
Character.to.UperCase(‘a’);)
How Does this Idea Extend to Fields?
• Fields (and even classes) can also be static or non-static
• A class called Dog(), that will create new instances of dog
objects each time it is invoked(run/executed)

, • numberOfLegs field is ALWAYS going to be 4. So, there is
no need for every dogs to have it’s own copy of this field
• It is better for Class Dog() to have single, static field, that
the individual objects would then just reference if needed
• But hairColour would be non-static field, because dogs have
a wide variety of different colours. So, each object would
need its own copy of this field
• Non-static field, or fields that belong to an instance of a
class (an object), are also sometimes known as “instance
variables”


Method Declarations, Headers and Signatures:
What is a Method Declaration?
• The method declaration is the whole bang-shoot, The
entire method.
What is a Method Header?
• The first line of the method declaration.
What is the Method Signature?
• The method name and any parameters.
Related Terminology:
• public: is the access modifier
• static: specifies if the method belongs to the class, or
object of the class
• void/othertypes: this is the types of data that the
method returns


Characters have value:

Infos sur le Document

Schooljaar
200
Publié le
19 février 2025
Nombre de pages
6
Écrit en
2024/2025
Type
Resume
$7.16

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Vendu
0
Abonnés
0
Éléments
1
Dernière vente
-



Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Vous travaillez sur vos références ?

Créez des citations précises en APA, MLA et Harvard avec notre générateur de sources gratuit.

Vous travaillez sur vos références ?

Foire aux questions