Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Very Beginner\'s Java questions. Please make the answers short so even beginners

ID: 3733588 • Letter: V

Question

Very Beginner's Java questions. Please make the answers short so even beginners can understand. Thank you!

1. What is Inheritance and when?why do we use it?

2. What is Polymorphism and when?why do we use it?

3. What is Encapsulation and when?why do we use it?

4. What is Loose Coupling and when?why do we use it?

5. What is Overriding methods and when?why do we use it?

6. What is Overloading methods and when?why do we use it?

7. When using debugger, what is Step over and Step into?

8. What are some benefits of overriding toString, equals, compareTo?

Explanation / Answer

Answer:1--  Inheritance is the property by virtue of which one class acquire the property of another class.The class whose property is acquired ,is called as superclass or parent class and the class which aquires the property is called as subclass or childclass.It enables new objects to take on properties of existing objects.

Inheritance has 5 types,

Answer:2-- Polymorphism is the characterstic of being able to assign a different meaning or usage to something in different contexts. It enables one entity to be used as a generak category for different type of action.(i.e Same Name Function, Different Parameters ).

Polymorphism Exists in three forms,

Answer:3-- Encapsulation-- The Wrapping up of Data and Method in a single unit is called Encapsulation.Encapsulation means as much as shielding.It seperates the external aspects of an object from the internal implementation details of the objects, which are hidden from other objects.

Example -- Class.

Answer:4-- Loose Coupling in an approach to interconnecting the components or elements in a system or network ,so that those components or elements depend on each other to the least extent practicable. Loose Coupling means reducing dependencies of a class that use a different class directly.

Answer:5-- Overriding Method means fuction with the same definition having differnt behavior in different scope.It is used by a childclass to change the behaviour it inherited from it's parent class.

Ex. class A{

void add();

class B extends A {

void add(); // override method

}

}

Answer:6-- Overloading Method means more than one definition for a function in the same scope that works on different inputs.It is used to have one function that can operate on different data types.

Ex. class A{

void add(int x,int y);

void add(int x,int y, int z);// Method overloading

}

Answer:7-- Debugger is a computer program that is used to test and debug the other programs.

Step over will call the function and return, pausing the debugger on the line of code after the function.

Step into will call the function and pause the debugger on the first line of code inside the function.

Answer:8-- toString  method returns string representation of an object.

equals method is used to perform deep comparison (it compares whether the contents of two string objects are same or not ) .It performs case-sensitive comparion.

compareTo method is used to compare two string.