Skip to content

Instantly share code, notes, and snippets.

@rozer007
Last active November 25, 2021 07:50
Show Gist options
  • Save rozer007/5426c347b2f0c4873c0daf3fb1eaad29 to your computer and use it in GitHub Desktop.
Save rozer007/5426c347b2f0c4873c0daf3fb1eaad29 to your computer and use it in GitHub Desktop.
polymorphism and symbols in ruby
Q1) How to declare a symbol in ruby?
ans: Before the symbol name we need use ":" character to define a symbol.
Q2) How many type of polymorphism can be done in ruby?
ans: Two types : i) using inheritance
ii) using duck typing
Q3) What is duck typing in polymorphism ?
ans: It implements what can be implemented on the object rather than instance of the class.
Q4) Why polymorphism?
ans : It allow to peform many operation from a instance of single class using inheritance and duck typing in ruby.
Q1) What symbol use for inheritance in ruby?
a) >
b) <
c) ::
d) none of the aboves
ans: b) <
Q2) what will be the output of this statement:
class Cars
def tweek
puts "wooooommm"
end
end
class Bmw<Cars
def tweek
puts "grnnnnn"
end
end
bmw = Cars.new
puts bmw.tweek
a) "grnnnnn"
b) "wooooommm"
c) "wooooomm"
"grrnnnn"
d) none of the above
ans: b)
Q3) What will be the output this program?
class Cars
def tweek(bir)
bir.tweek
end
end
class Bmw<Cars
def tweek
puts "grnnnnn"
end
end
bmw = Cars.new
puts bmw.tweek(Bmw.new)
a) "grnnnnn"
b) "wooooommm"
c) "wooooomm"
"grrnnnn"
d) none of the above
ans: a)
Q4) what is be the output of this statement:
:pepcoder
puts :pepcoder.class
a) literal
b) Object
c) Symbol
d) None of the aboves
ans: c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment