-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex44a.rb
More file actions
28 lines (22 loc) · 943 Bytes
/
ex44a.rb
File metadata and controls
28 lines (22 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 1. Actions on the child imply an action on the parent
# 2. Actions on the child verride actions on the parent
# 3. Actions on the child alter the action on the parent
#Implicit Inheritance
# - define a function in the parent but NOT the child
class Parent
def implicit()
puts "PARENT implicit()"
end
end
# Define the Parent class, which contains a simple function to output a line of text called 'implicit'.
class Child < Parent
end
# Child is an empty class, inheriting everything from the Parent class
dad = Parent.new()
# Create new instance of Parent class, called 'dad'
son = Child.new()
# Create new instance of Child class, called 'son'
dad.implicit()
# Call the implicit function defined in the Parent class on the 'dad' instance of the Parent class (a base class)
son.implicit()
# Call the implicit function implicitly inherited from the Parent class for the 'son' instance of the Child class (a subclass)