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

1. How is an object \"instantiated\" in a cient program? Provide an example. Wha

ID: 3748981 • Letter: 1

Question

1. How is an object "instantiated" in a cient program? Provide an example. What two things make a constructor different from other methods in a class? 2. Explain how "information hiding" is accomplished with attributes and behaviors of a class. When would a method be declared as private instead of public? Give an example. 3. What does the term "encapsulation" mean in terms of defining objects of a class? How does that make it possible to write code time-efficiently and cost-effectively? 4. When is the word "static" used in defining variables or methods? How does this change the way that a client program refers to it? 5. When is the keyword "this" used? When is the keyword "null" used?

Explanation / Answer

1)

Instantiation means creating an object for a class.

public class Student
{
public string Name;
public string stdentId;
public int midGrade;
public int finalGrade;

}

Student obj = new Student();

obj.Name = "Pranesh";
obj.midGrade = 25;
obj.finalGrade = 100;

2)

Information hiding:

It is the process of hiding or restrictricting the some of the objects components like for example age, phone number etc.

Here the own class only can call its method dep, no people can use this method outside the class to deposit the money in his account.

3)

It is the process of combining code and data together.

by using encapsulation we can have control over the data, data hiding and easy to test the code.

public class Stud{  

private String nam;  

public String getName(){  

return nam;  

}  

public void setName(String name1){  

this.nam=name1

}

}

class Check{  

public static void main(String[] args){

Stud=new Stud();  

s.setName("Prabesh");  

System.out.println(s.getName());  

}  

}  

  

4)

The static is mainly for the memory management.

If a value has to be same for all the instance of a class then it can be used as static.

If anything is declared in static then the client can call it without creating the instance for the class.

5)

If you want to refer the current instance or object of a class then we can use the word this.

Generally it is not a keyword, it is invented to use during the absence of something.

Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again.

Constructor Method 1) It does not have any returm type 1) It should have some return type 2) Should be same as class name 2) can be of any name