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

**Please provide explanations for the topics mentioned as well as simple example

ID: 3826352 • Letter: #

Question

**Please provide explanations for the topics mentioned as well as simple examples for each.

Each explanation should include an example (or examples).

The examples should:
- be easy to understand.
- include all componenets (class/method declaration etc...).

________________________________________________________________-

Study Guide | Programming II


1. Given partial definitions of a superclass and subclass – including instance variable declarations, method declarations, and Java documentation comments - be able to write the method bodies

2. Explain how superclasses and their extending subclasses are used to implement polymorphism, and the benefits of inheritance

3. Explain encapsulation – the benefits of encapsulation and why breaking encapsulation is considered a violation of the “prime directive” of OOP

4. Compare and contrast abstract superclass, concrete superclass, and interface

5. Compare and contrast:

a. Java’s Comparable and Comparator interfaces
b. arrays and linked lists
c. the equals method and the “==” operator
d. instance variables and static “class” variables

6. Understand code that manipulates abstract stacks and queues, using stack methods push, pop, peek, and isEmpty, and queue methods append, serve, and isEmpty

7. Understand and be able to write code that performs simple operations on linked lists of nodes

8. Given the definition of a simple recursive method, show what will be returned for a given call, and be able to write a simple recursive method

Explanation / Answer

1)Given partial definitions of a superclass and subclass – including instance variable declarations, method declarations, and Java documentation comments - be able to write the method bodies.

A) A subclass inherits state and behavior from all of its parentclass.Subclass is a class that derives from another class.The term superclass refers to a class's direct parentclass as well as all of its ascendant classes.


instance variable declarations:

public class instant {

int a;
a= 100;

public static void main(String[] args)
{

int localInt;
u = 9000;
}

}

Overriding
---------------


class A{
   int x = 0, y = 0;
   void move(int A, int B) { x += A; y += B; }
}
class SlowPoint extends A //INHERITS PARENT A CLASS
{
   int xLimit, yLimit;
   void move(int A, int B) {
       super.move(limit(A, xLimit), limit(B, yLimit));
   }
   static int limit(int d, int limit) {
       return d > limit ? limit : d < -limit ? -limit : d;
   }
}

Java documentation comments

Java documentation is a tool which comes with JDK and it is used for generating Java code documentation in HTML format from Java source code, which requires documentation in a predefined format.

public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hi!");
}
}

2.Explain how superclasses and their extending subclasses are used to implement polymorphism, and the benefits of inheritance

public Object()
{

}
Class Animal {
public Animal(){

//call here like super()
}

class lizard extends Animal {
public Lizard(your args) {
//here the super() call
}
}

}

benefits of inheritance
1)Reusability - To use public methods of parent class without rewriting the same.
2)Extensibility - Extending the parent class logic as per business logic of the child class.
3)Data hiding - Parent class can decide to keep some derived data private so that it cannot be altered by the Child class.

3.Explain encapsulation – the benefits of encapsulation and why breaking encapsulation is considered a violation of the “prime directive” of OOP

Encapsulation is wrapping of data and code acting on the data (methods) together as a single unit.Encapsulation promotes
a)Maintenance Code changes can be made independently.
b)Increases usability.

4.Compare and contrast abstract superclass, concrete superclass, and interface

The difference is that a concrete class can be instantiated because it inherits or provides the implementation for all of its methods.
An abstract class cannot be instantiated because at least one method has not been implemented.
Here abstract classes are meant to be extended.
Abstract class can have static, final variable with any access specifier.
interface can have only static constant variable by default.


5.Compare and contrast: a. Java’s Comparable and Comparator interfaces b. arrays and linked lists c. the equals method and the “==” operator d. instance variables and static “class” variables?

Comparable interface:
public class State implements Compareint{
  
public int compareTo(Object arg0) {
State A=(State) arg0;
return (this.stateId < A.stateId ) ? -1: (this.stateId > A.stateId ) ? 1:0 ;
}}


Comparator interface:

public class StateSortByIdComparator implements Comparator<State>{

  
public int compare(State A,State B) {

return (A.getStateId() < B.getStateId() ) ? -1: (A.getStateId() > B.getStateId() ) ? 1:0 ;
}

}

Instance variables:

Instance variables belong to the instance of a class. And every instance of that class or an object has it's own copy of that variable. Changes that made to the variable don't reflect in other instances of that class.
public class Product {
public int A;
}

Class variables:

Class variables are known as static member variables and there is only one copy of that variable that is shared with all instances of that class. If changes are made to that Class variables, all other instances will see the effect of the changes.
public class Product {
public static int A;
}


8. Given the definition of a simple recursive method, show what will be returned for a given call, and be able to write a simple recursive method

A)Recursion is a best programming technique you can use in Java, in which a method calls itself to solve some problem. A method that uses this technique isrecursive.
The definition of factorial is recursive because the definition includes the factorial method itself.
public class RecursionEx {
static void print(){
System.out.println("hi");
print();
}
  
public static void main(String[] args) {
print();
}
}

Thank you I had provided you the answers based on my research and knowledge thank you.