You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# In Ruby, you can define instance methods that are exclusive to a specific class.
# This means that the method is only available to instances of that class and not to instances of any other class, even if they are subclasses of the original class.
# This is achieved by defining the method within the class definition, and it will not be inherited by any subclasses.
class Parent
def say_hello_parent
"Hello from the parent!"
end
end
class Child < Parent
def say_hello_child
"Hello from the child!"
end
end
parent1 = Child.new
parent2 = Child.new
puts parent1.say_hello_parent # Output: Hello from the parent.
puts parent2.say_hello_parent # Output: Hello from the parent.
child1 = Child.new
child2 = Child.new
puts child1.say_hello_child # Output: Hello from the child.
puts child2.say_hello_child # Output: Hello from the child.