Docsity

ការទទួលមរតក (Inheritance), Quizzes of Programming Languages

Toggle sidebar
bg1
Page 1 of 7
ព្រះរាជាណាចព្ររម្ពុជា
ជាតិ សាសនា ព្រះម្ហារសព្ត
3
សារលវិទ្យាល័យ អាសុ៊ី អឺរ ុប
មហាវិទ្យាល័យវិទ្យាសាស្ត្រ និងបច្ចេកវិទ្យា
3
សំណួ រ
មម្មរៀនទ្យ៊ី៦៖ ការទ្យទ្យួលម្រតរ (Inheritance)
ម្ុខវិជាា ៖ Basic Object Programming Language
3
១. ចូរពន្យល់ពីការទទួលមរតករបស់ Class មួយ ពី Class មួយទទៀត ទោយផ្តល់ជាឧទាហរណ៍ បញ្ជា ក់។
២. ចូរន្ិយាយពីការទ្បី super ្ពមទាាំងទលីកយកឧទាហរណ៍ មកបញ្ជា ក់។
៣. ចូរន្ិយាយអាំពីភាពខុសគ្នា រវាង Method overloading ន្ិង Method overriding ្ពមទាាំងទលីកយក
ឧទាហរណ៍ មកបញ្ជា ក់។
៤. ចូរន្ិយាយពីការទ្បី Abstract class ន្ិង Abstract method ន្ិងទលីកយកឧទាហរណ៍ មកបញ្ជា ក់។
៥. ចូរន្ិយាយពីការទ្បីពាកយ final ្ពមទាាំងទលីកយកឧទាហរណ៍ មកបញ្ជា ក់។
៦. Which of this keyword must be used to inherit a class?
ក. super
ខ. this
គ. extent
ឃ. extends
៧. A class member declared protected become a member of subclass of which type?
ក. public member
ខ. protected member
គ. private member
ឃ. static member
៨. Which of these is correct way of inheriting class A by class B?
ក. class B + class A {}
ខ. class B inherits class A {}
គ. class B extends A {}
ឃ. class B extends class A {}
pf3
pf4
pf5

Partial preview of the text

Download ការទទួលមរតក (Inheritance) and more Quizzes Programming Languages in PDF only on Docsity!

មម្ មរៀនទ្យ៊ី ៦៖ ការទ្យទ្យួ លម្រតរ (Inheritance) ម្ុខវិជាា៖ Basic Object Programming Language

១. ចូរពន្ យល់ពីការទទួលមរតករបស់ Class មួយ ពី Class មួយទទៀត ទោយផ្តល់ជាឧទាហរណ៍បញ្ជាក់ ។

២. ចូរន្ិ យាយពីការទ្ បី super ្ពមទាាំងទលីកយកឧទាហរណ៍មកបញ្ជ ាក់។

៣. ចូរន្ិ យាយអាំពីភាពខុសគ្ន ារវាង Method overloading ន្ិ ង Method overriding ្ពមទាាំងទលីកយក ឧទាហរណ៍មកបញ្ជាក់ ។

៤. ចូរន្ិ យាយពីការទ្ បី Abstract class ន្ិ ង Abstract method ន្ិ ងទលីកយកឧទាហរណ៍មកបញ្ជ ាក់។

៥. ចូរន្ិ យាយពីការទ្ បីពាកយ final ្ពមទាាំងទលីកយកឧទាហរណ៍មកបញ្ជ ាក់។

៦. Which of this keyword must be used to inherit a class? ក. super ខ. this គ. extent ឃ. extends

៧. A class member declared protected become a member of subclass of which type? ក. public member ខ. protected member គ. private member ឃ. static member

៨. Which of these is correct way of inheriting class A by class B? ក. class B + class A {} ខ. class B inherits class A {} គ. class B extends A {} ឃ. class B extends class A {}

៩. What is subclass in Java? ក. A subclass is a class that extends another class ខ. A subclass is a class declared inside a class គ. Both above ឃ. None of the above

១០. If class B is subclassed from class A then which is the correct syntax. ក. class B:A {} ខ. class B extends A {} គ. class B extends class A {} ឃ. class B implements A {}

១១. Which of these keywords can be used to prevent the method overriding? ក. static ខ. constant គ. protected ឃ. final

១២. Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B? ក. super(void); ខ. superclass.(); គ. super.A(); ឃ. super();

១៣. What is the use of final keyword in Java? ក. When a class is made final, a subclass of it cannot be created. ខ. When a method is final, it cannot be overridden. គ. When a variable is final, it can be assigned value only once. ឃ. All of the mentioned

១៤. super keyword in Java is used to: ក. Refer immediate parent class instance variables. ខ. Invoke immediate parent class methods. គ. Invoke immediate parent class constructor. ឃ. All of the mentioned

១៥. Which two classes use the Shape class correctly? A. public class Circle implements Shape {

១៦. What will be the output of the following Java Program?

  1. class A
  2. {
  3. int i;
  4. void display()
  5. {
  6. System.out.println(i);
  7. }
  8. }
  9. class B extends A
  10. {
  11. int j;
  12. void display()
  13. {
  14. System.out.println(j);
  15. }
  16. }
  17. class inheritance_demo
  18. {
  19. public static void main(String args[])
  20. {
  21. B obj = new B();
  22. obj.i=1;
  23. obj.j=2;
  24. obj.display();
  25. }
  26. } ក. 0 ខ. 1 គ. 2 ឃ. Compiler error

១៧. What will be the output of the following Java Program?

  1. class A
  2. {
  3. int i;
  4. }
  5. class B extends A
  1. int j;
  2. void display()
  3. {
  4. super.i = j + 1 ;
  5. System.out.println(j + " " + i);
  6. }
  7. }
  8. class inheritance
  9. {
  10. public static void main(String args[])
  11. {
  12. B obj = new B();
  13. obj.i= 1 ;
  14. obj.j= 2 ;
  15. obj.display();
  16. }
  17. } ក. 2 2 ខ. 3 3 គ. 2 3 ឃ. 3 2

១៨. What will be the output of the following Java Program?

  1. class A
  2. {
  3. public int i;
  4. public int j;
  5. A()
  6. {
  7. i = 1;
  8. j = 2;
  9. }
  10. }
  11. class B extends A
  12. {
  13. int a;

ខ. this គ. upper ឃ classname

២៣. Static members are not inherited to subclass. ក. True ខ. False

r3s

១. ចូរពន្យល់ពី�រទទួលមរតករបស់ Class មួ យ ពី Class មួយទេទៀត េ�យផ�ល់�ឧ�ហរណ៍ប�� ក់។

�រទទួលមរតក (Inheritance) គឺ�េ�ល�រណ៍សំ�ន់មួយក�� ង�រសរេសរកម�វ �ធីវត�� (Object-Oriented

Programming - OOP)។ �អនុ�� តឱ្យ Class មួ យ (ែដលេ�� Subclass ឬ Child Class)

ទទួល�នលក�ណៈសម្បត�ិ (Attributes) និងវ � ធី��ស� (Methods) �ំងអស់របស់ Class មួយេទៀត

(ែដលេ�� Superclass ឬ Parent Class)។

ឧ�ហរណ៍: េយ�ង�ចបេង��ត Class មួយេ�� ះ� "Animal" ែដល�នលក�ណៈសម្បត�ិដូ ច� "name" និង

"age" និងវ �ធី��ស�ដូច� "eat" និង "sleep"។ ប��ប់មក េយ�ង�ចបេង��ត Class ថ�ីេ�� ះ� "Dog"

ែដលទទួលមរតកពី Class "Animal"។ Class "Dog" នឹងទទួល�នលក�ណៈសម្បត�ិ និងវ � ធី��ស�ដូច��នឹង

Class "Animal" ប៉ុែន��ក៏�ច�នលក�ណៈសម្បត�ិ និងវ � ធី��ស�បែន�ម��ល់ខ� នផងែដរ ដូច� "bark"។�

២. ចូរន្ិ�យពី�រទ្បី super � ម� ាំងទលីកយកឧ�ហរណ៍មកប�� ក់។

�ក្យគន�ឹះ "super" ្រ ត � វ�នេ្រប�្រ�ស់េដ�ម្បី េ�វ �ធី��ស� ឬលក�ណៈសម្បត�ិរបស់ Superclass ពីក�� ង

Subclass ។

ឧ�ហរណ៍: ្រ បសិនេប� Subclass �នវ �ធី��ស�ដូច��នឹង Superclass េហ�យេយ�ងចង់េ្រប�វ � ធី��ស�របស់

Superclass េយ�ង�ចេ្រប� "super" េដ� ម្បីេ��។

៣. ចូរន្ិ�យ�ំពី�ពខុស�� រ�ង Method overloading ន្ិង Method overriding � ម�ាំងទលីកយក

Method Overloading: គឺ�របេង��តវ �ធី��ស�ែដល�នេ�� ះដូច��ប៉ុែន��ន្របេភទ

Method Overriding: គឺ�របេង��តវ �ធី��ស�ែដល�នេ�� ះ ្រ បេភទ�៉��ែម៉្រត

និងចំនួន�៉��ែម៉្រតដូ ច��នឹងវ �ធ��ស�េ�ក�� ង Superclass ប៉ុែន��ន�រអនុវត�ខុស��។

៤. ចូរន្ិ�យពី�រទ្បី Abstract class ន្ិង Abstract method ន្ិងទលីកយកឧ�ហរណ៍មកប�� ក់។

Abstract Class: គឺ� Class ែដល�នវ �ធី��ស� Abstract �៉ងេ�ច�ស់មួយ។

Abstract Method: គឺ�វ �ធី��ស�ែដល្រត � វ�ន្រប�សេ�ក�� ង Abstract Class

ប៉ុែន�មិន�ន�រអនុវត�េ�ក�� ង Abstract Class េ�ះេទ។ �្រត � វែត្រត � វ�នអនុវត�េ�ក�� ង Subclass ។

ឧ�ហរណ៍: េយ�ង�ចបេង��ត Abstract Class េ�� ះ� "Shape" ែដល�ន Abstract Method េ�� ះ�

"calculateArea"។ Subclass ដូច� "Rectangle" និង "Circle" នឹង្រត � វែតអនុវត�វ �ធី��ស� "calculateArea"

៥. ចូរន្ិ�យពី�រទ្បី �កយ final � ម�ាំងទលីកយកឧ�ហរណ៍មកប�� ក់។

�ក្យគន�ឹះ "final" ្រ ត � វ�នេ្រប�្រ�ស់េដ�ម្បីប��ញ� Class, Method ឬ Variable

ឧ�ហរណ៍: ្រ បសិនេប�េយ � ង្រប�ស Class មួ យ� "final" េ�ះ�មិន�ច្រត � វ�នទទួលមរតក�នេទ។ ្រ

បសិនេប� េយ�ង្រប�ស Method មួ យ� "final" េ�ះ�មិន�ច្រត � វ�ន Override �នេទ។