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

Java review: What is a constructor? When defining classes, how do you define the

ID: 3860931 • Letter: J

Question

Java review:

What is a constructor?

When defining classes, how do you define the attributes? How about the setters & getters?

If you need a variable to keep track of the sum of things, what is that variable called?

What is the scope of a variable?

What is encapsulation, and how does it relate to data hiding?

What’s the difference between a class and an object?

What is a wrapper class? How do you use it, and why?

Give an example of creating a new instance of a Student class.

What are the different types of loops, and how do they work?

How should we decide what type of loop to use?

When you use an if-statement, how should you write the condition?

How does a switch-case statement work? What is required so the logic won’t fall through?

When should you use an if-statement vs a switch-case statement?

What is a method, and describe the parts of a method’s header.

How do you pass a variable to a method? How do you pass an array to a method?
How do you pass an arrayList to a method?

What is method overloading?

How are fields in a class initialized?

What is an array and how does it work? How do you define an array?

How do you change values in an array? How do you initialize an array? (2 ways – what are they?)

What is an arrayList and how does it work? How do you define an arrayList?

How do you add elements to an arrayList? Change? Delete?

What is the difference between an array and an arrayList?

What is a String? What is concatenation?

Explanation / Answer

Please find below ansers of first 4 parts as per chegg guidelines.

1. In OOPS a constructor is a public method of a class or structure that initializes an object it. A constructor has the same name as the class, and can be used to set the values of the members of an object to default or to user-defined values.

2. Attributes can be define under three different access specifier such as Private, Public, Protected like :

Class ABC {

private : int x;

float y;

public : int z;

String s;

}

3. You can create any variable to keep track of the sum of things. Please take care of initializing that variable with 0.

for eg: int sum = 0 (any name of the variable let say x or y, I have taken sum)

sum = sum + 5 (or any other value)

4. A scope is a region of the variable, that is where a variable can be accessible. There are two places, where variables can be declared

a. Inside a function or a block which is called local variables,

b. Outside of all functions which is called global variables

Please ask other parts as separate question as per chegg policy.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote