← VCE Software Development U4O1

Public attributes and methods

A public member has no leading underscore, so code inside or outside the class can access it, e.g. self.name in the class or pet.name outside it.

Understanding Public attributes and methods in VCE Software Development U4O1

What it does: A public attribute like name can be accessed from outside the class with object.attribute. The leading underscore marks a member as protected by convention. With no underscore, speak is public. Inside the class, attributes are reached through self. A bare age would be an undefined variable.

Common mistakes: Without self., this only sets a local variable, so no public attribute is created. It should be self.name = name so pet.name works outside the class. Every method needs self as its first parameter so it can use self.name. It should be def speak(self):.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 3–79) and word search (Modules 3–114).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which attribute is public?
self.nameself._name
Matches
self._name = name # meant to be public
↓
The leading underscore makes the attribute protected by convention, not public. Use self.name to make it public.
Applying
Meanings
Term
self.name
Meaning
A public member has no leading underscore, so code inside or outside the class can access it, e.g. self.name in the class or pet.name outside it.
Practice
class Pet:
Testing
Gaps
pet.()
Check Answer
Spots
2 def __init__(self, name):
3 name = name

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Zebra' badge — Pattern Matcher, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which attribute is public?
A. self._name
B. self.name ✓
A public attribute has no leading underscore, so code inside or outside the class can use it.
2. Which line reads a public attribute from outside the class (pet is an object)?
A. print(pet.name) ✓
B. print(self.name)
Outside the class there is no self. You use the object's name, such as pet.name.
3. True or false: a public method can be called from outside the class, e.g. pet.speak().
A. True ✓
B. False
Public methods have no leading underscore and can be called from anywhere, including outside the class.
4. Which method name is public?
A. def speak(self): ✓
B. def _speak(self):
The leading underscore marks a member as protected by convention. With no underscore, speak is public.
5. Which line changes a public attribute from outside the class?
A. self.name = 'Rex'
B. pet.name = 'Rex' ✓
Outside the class you use the object variable (pet.name). self only works inside the class's methods.

Match the Pairs

self.name = name → Creates a public attribute with no leading underscore, so any code can read or change it
def speak(self): → Defines a public method that can be called from inside or outside the class
Code outside the class can read a public attribute using the object name and a dot → print(pet.name)
Code outside the class can call a public method on an object → pet.speak()
self._name = name # meant to be public → The leading underscore makes the attribute protected by convention, not public. Use self.name to make it public.
print(name) # outside the class → The attribute is accessed without an object. Outside the class a public attribute needs the object and a dot, like pet.name.

Key Term

self.name
A public member has no leading underscore, so code inside or outside the class can access it, e.g. self.name in the class or pet.name outside it.

Fill in the Blanks

1. pet = Pet("Milo") pet.speak() print(pet.name)
Hint: Type the name of the public method that is called from outside the class to make the pet bark.
2. pet = Pet("Milo") print(pet.name)
Hint: Type the object variable used to reach the public attribute from outside the class.
3. class Pet: def speak(self): print("Woof!")
Hint: Type the first parameter that every public method receives so it can refer to its own object.
4. def intro(self): self.speak()
Hint: Type the keyword that refers to the current object when one method calls another inside the class.
5. pet = Pet("Milo") print(pet.name) pet.speak()
Hint: Type the class name used to create the object, so its public members can be used outside the class.

Spot the Error

Question 1
A class Pet:
B def __init__(self, name):
C name = name
D pet = Pet("Rex")
E print(pet.name)
Line C — Without self., this only sets a local variable, so no public attribute is created. It should be self.name = name so pet.name works outside the class.
Question 2
A class Pet:
B def __init__(self, name):
C self.name = name
D def speak():
E print(self.name, "woofs")
F Pet("Rex").speak()
Line D — Every method needs self as its first parameter so it can use self.name. It should be def speak(self):.
Question 3
A class Dog:
B def _bark(self):
C print("Woof!")
D rex = Dog()
E rex.bark()
Line B — The leading underscore means the method is not public, so rex.bark() fails from outside the class. A public method has no underscore: def bark(self):.
Question 4
A class Car:
B def __init__(self, make)
C self.make = make
D car = Car("Kia")
E print(car.make)
Line B — The def line is missing its colon. It should be def __init__(self, make): so the public attribute self.make can be set.
Question 5
A class Player:
B def __init__(self):
C self.__score = 0
D p = Player()
E print(p.score)
Line C — The double underscore makes score private, so p.score fails outside the class. A public attribute has no leading underscore: self.score = 0.

Student with a class code? Join your class →