LISP Questions & Answers – Class

«
»

This set of LISP Multiple Choice Questions & Answers (MCQs) focuses on “Class”.

1. Which makes it possible to define generic functions?
a) Lisp
b) CLOS
c) Class
d) Object-Oriented programming
View Answer

Answer: b
Explanation: Common Lisp Object System makes it possible to define generic functions.
advertisement

2. What is meant by collection of methods the same name?
a) Lisp class
b) Class
c) Generic function
d) None of the mentioned
View Answer

Answer: c
Explanaton: Each collection of methods that share the same name is called a generic function.

3. Which keyword is used to define the method?
a) Defun
b) Destruct
c) Demake
d) Defmethod
View Answer

Answer: d
Explanation: Defmethod is used for defining the method.

4. Which class can help to select a method?
a) Nonoptional argument
b) Class
c) Method
d) None of the mentioned
View Answer

Answer: a
Explanation: Any nonoptional argument class can help to select a method.

5. Which require sophisticated precedence computation?
a) Superclass
b) Multiple Superclass
c) Subclass
d) None of the mentioned
View Answer

Answer: b
Explanation: Multiple superclasses require sophisticated precedence computations.
advertisement

6. What is the output of the given statement?

span class="sy0"> * (defstruct triangle (base 0) (altitude 0))
* (defun area (figure) (cond ((triangle-p figure) (* 1/2 (triangle-base figure) (triangle-altitude figure)))))
* (setf triangle (make-triangle :base 2 :altitude 3))
* (area triangle)

a) Triangle
b) 7
c) 3
d) 10
View Answer

Answer: c
Explanation: This statement will compute the area of triangle.
Output:
3

7. What is the output of the given statement?

span class="sy0"> * (defstruct circle (radius 0))
* (defun area (figure) (cond ((circle-p figure) (* pi (expt (circle-radius figure) 2)))))
* (setf circle (make-circle :radius 11))
* (area circle)

a) 44
b) 380
c) 382
d) 380.132
View Answer

Answer: d
Explanation: This statement will compute the area of circle using given statement.
Output:
380.132711084365
advertisement

8. What is the output of the given statement?

span class="sy0"> * (defmethod area ((figure rectangle)) (* (rectangle-width figure) (rectangle-height figure)))

a) Area
b) Rectangle
c) Height
d) Error
View Answer

Answer: d
Explanation: This statement will return an error because of misplacing of brackets.

9. What is the output of the given statement?

advertisement
span class="sy0"> * (defclass article() ((title :accessor article-title :initarg :title) (author :accessor article-author :initarg :author)))

a) Article
b) <STANDARD-CLASS
c) <STANDARD-CLASS ARTICLE>
d) None of the mentioned
View Answer

Answer: c
Explanation: This statement will create an class by using defclass keyword.
Output:
#<STANDARD-CLASS ARTICLE>

10. What is the output of the given statement?

span class="sy0"> * (defclass article() ((title :accessor article-title :initarg :title) (author :accessor article-author :initarg :author)))
* (defclass computer-article (article) ())
* (defclass business-article (article) ())
* (defclass political-article (article) ())
* (setf articles (list (make-instance 'business-article :title "Memory Prices down")))

a) Business article
b) Political article
c) Business article
d) <BUSINESS-ARTICLE {Random Number}>
View Answer

Answer: d
Explanation: This statement will make the book name under the main title of business articles.
Output:
(#<BUSINESS-ARTICLE {AC04B11}>)

Sanfoundry Global Education & Learning Series – LISP Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn