Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Core java - Interview Questions and Answers for 'Commvault' - 2 question(s) found - Order By Newest | ||||
Frequently asked to fresh graduates and less experienced developers. Among the first few questions in many interviews. | ||||
| ||||
Ans. Composition - has-a relationship between objects. Inheritance - is-a relationship between classes. Composition - Composing object holds a reference to composed objects and hence relationship is loosely bound. Inheritance - Derived object carries the base class definition in itself and hence its tightly bound. Composition - Used in Dependency Injection Inheritance - Used in Runtime Polymorphism Composition - Single class objects can be composed within multiple classes. Inheritance - Single class can only inherit 1 Class. Composition - Its the relationship between objects. Inheritance - Its the relationship between classes. | ||||
Sample Code for inheritance Sample Code for composition | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java concepts   inheritance  object oriented programming (oops)  oops concepts   composition  object oriented programming (oops)  oops concepts   inheritance  object oriented programming (oops)  inheritance vs composition  object oriented programming (oops)  oops concepts Asked in 29 Companies basic   frequent | ||||
Try 5 Question(s) Test | ||||
Related Questions | ||||
Difference between Composition and Inheritance ? | ||||
Which of the following Java feature promotes access protection or Hiding ? a. Inheritance b. Encapsulation c. Abstraction d. Composition | ||||
Which of the following is tightly bound ? Inheritance or Composition ? | ||||
Can we compose the Parent Class object like this ? | ||||
Does use of Final class enforces composition over Inheritance in Java ? | ||||
Which of the following Java features facilitates Dependency Injection - Inheritance or Composition ? | ||||
How are the concept of Association related to Composition and Inheritance ? | ||||
Is dependency injection possible if we don't have inheritance / Composition ? | ||||
What is composition ? | ||||
| ||||
Ans. 1. Stack Segment - Contains primitives, Class / Interface names and references. 2. Heap Segment - Contains all created objects in runtime, objects only plus their object attributes (instance variables), Static variables are also stored in heap. 3. Code Segment - The segment where the actual compiled Java bytecodes resides when loaded | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   memory   memory management   stack memory   heap memory   code segment memory   advanced Asked in 9 Companies expert   frequent | ||||
Try 6 Question(s) Test | ||||
Related Questions | ||||
What are different ways to create String Object? Explain. | ||||
Does garbage collection guarantee that a program will not run out of memory? | ||||
Describe, in general, how java's garbage collector works ? | ||||
Describe what happens when an object is created in Java ? | ||||
What are various types of Class loaders used by JVM ? | ||||
Why two types of memory - stack and heap are required by Java ? | ||||
Should we override finalize method ? | ||||
What are strong, soft, weak and phantom references in Java ? | ||||
Which memory areas does instance and static variables use ? | ||||
Can we call the garbage collector explicitly ? | ||||