Rédigé par des étudiants ayant réussi Disponible immédiatement après paiement Lire en ligne ou en PDF Mauvais document ? Échangez-le gratuitement 4,6 TrustPilot
logo-home
Document preview thumbnail
Aperçu 3 sur 22 pages
Autre

CP213 Object-Oriented Programming ACTUAL VERIFIED Practice sample Final EXAM 2025 REVIEW UPDATE Wilfrid Laurier University

Document preview thumbnail
Aperçu 3 sur 22 pages

CP213 Object-Oriented Programming ACTUAL VERIFIED Practice sample Final EXAM 2025 REVIEW UPDATE Wilfrid Laurier University

Aperçu du contenu

CP213 Object-Oriented Programming ACTUAL VERIFIED Practice sample Final EXAM 2025 REVIEW
UPDATE Wilfrid Laurier University




213 FINAL EXAM REVIEW

Protected access: child classes to this class can access the method/variables even if
they aren't in the same package
**There are 2 classifications of instance variables & methods that allow them to be accessed
by name in a derived class** → one of them is protected access (always gives access)


➔ If a method/instance variable is modified by protected (rather than
public/private) → it can be accessed by name inside its own class definition
◆ it can be accessed by name inside any class derived from it
◆ it can also be accessed by name in the definition of any class in the
same package (even if the class in the same package is not derived
from it)
◆ Can be accessed in a different package if the class is derived from it

★ Example: consider the class HourlyEmployee that was derived from the base class
Employee.




If the private instance variables name & hireDate had been marked protected in the
class Employee, the definition of toString in the derived class HourlyEmployee could
be simplified to the following: (basically removed the “get”)




Pitfall: A Restriction on Protected Access ★

● A class can access its own classes’ inherited variables & methods that are marked
protected in the base class, but cannot directly access any such instance variables
● For example, n is an instance variable of the base class B & an instance variable of the
derived class D. D can access n whenever n is used as an instance variable of D, but D
cannot access n when n is used as an instance variable of B.

, ● If the classes B and D are in the same package, you will not get the error message
because, in Java, protected access implies package access.


Package/Friendly/Default access: each class that is derived from the same
package has access to this method/variables
**There are 2 classifications of instance variables & methods that allow them to be accessed
by name in a derived class** → one of them is package access (gives access if the derived class
is in the same package as the base class)


● If you do not place any of these modifiers (public, private, or protected) before
an instance variable or method definition → then the instance variable/method
can bg accgssgd bD namg insidg Ēhg dgfiniĒion of anD class in Ēhg samg
packagg buĒ noĒ ouĒsidg of Ēhg packagg → package access
○ Use package access in situations → package of cooperating classes that
act as a single encapsulated unit
○ Package access is more restricted than protected
○ Package access gives more control to the programmer defining the
classes
○ If you control the package directory (folder) → you control who is allowed
package access

Pitfall: Forgetting about the default package ★

● If a class in your current directory is not in any other package → then it is in
the default package
● If an instance variable/method has package access → then it can be accessed
by name in the definition of any other class in the default package




Public access: Any class can access this regardless of package or whatever
➔ The public access modifier is the direct opposite of the private access
modifier
◆ A class, method or variable can be declared as public → is accessible
from any class
◆ It can be accessed in its own class
◆ Can be accessed from a different class
◆ Can be accessed from a different package

, Private access: Means that only members of this class have access to this method/
variable

➔ The most restricted access level
◆ Can only be accgssgd in iĒs own class C samg packagg

➔ Class & interfaces cannot be private
➔ Variables that are declared private can be accessed outside the class → if
public getter methods are present in the class


★ ALL 4 ACCESS (private, public, package, protected)

Infos sur le Document

Publié le
16 septembre 2025
Nombre de pages
22
Écrit en
2025/2026
Type
Autre
Personne
Inconnu
$15.99

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

Seller avatar
Les scores de réputation sont basés sur le nombre de documents qu'un vendeur a vendus contre paiement ainsi que sur les avis qu'il a reçu pour ces documents. Il y a trois niveaux: Bronze, Argent et Or. Plus la réputation est bonne, plus vous pouvez faire confiance sur la qualité du travail des vendeurs.
smartzone
3.6
(615)
Vendu
3404
Abonnés
2297
Éléments
14731
Dernière vente
7 heures de cela



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