Different methods of writing a set

Descriptive passages in fiction Example:

Different methods of writing a set

Throwing exceptions Get and Set methods We were able to create objects of the Student and initialise the variables of the object using the constructor. But after that, we can no longer change the values the variables hold.

The following statement would result in an error since the variables were declared to be private. These are commonly known as get and set methods. Get methods provide access to the value a variable holds while set methods assign values to the variables of the objects. First, we shall see how we write a method.

In order to set a variable to a new value, the method needs arguments similar to how the parameterised constructors required details such as rollNumber, name and marks.

These required arguments are specified in the method header within the parentheses by specifying the variable name and a data type for that variable name.

A set method for name looks as shown below: If we wish to set the name for the first Student object s1 which we have created, we use the following statement: As we have earlier said, methods are capable of returning values.

What are the 3 methods in writing sets

These values can be of any primitive data type or reference type like a class. Here, we will be returning a String. The data type that is going to be returned in specified in the method header instead of the word void. We have used the word void till now to indicate that a method does not return any value.

The get method for name would be the following: The variable or value that is to be returned follows the return keyword. We can specify not just a variable name but also a constant or an expression. Also, the return statement should be the last line in a method that returns a value.

Once the return statement is reached, the lines of code that follow the return statement would not be executed. In this particular case, we cannot write any statements after the return statement. This is because unreachable code generates compilation errors.

Unreachable code refers to those statements which can never be executed. Consider the following get method for name.

This is because, once the return statement is encountered, the remaining lines of code in that method would be ignored. Therefore, the above code produces compilation errors. However, in certain circumstances, we can provide a return statement and also write code following that statement when we use decision making statements.

We will look into it alter on. Now, that we have written a get method, we shall see how we can use it. We can invoked the getName method a Student object, and the returned value can be stored in a variable, can be printed on the screen or can be used for any other purpose.

In the following statement, the value returned by getName is stored in the variable aName. We can also directly print the returned value by invoking the method within the parentheses in the following way: But what exactly is the use of these get and set methods?

Instead of providing these methods, we could have simply made the variables public and they could be accessed in the following way instead of using get and set methods.

But that isn't the preferred way for programmers. When data is easily accessible in that way, data isn't secure. One who uses the class can easily assign the marks1 of a Student with the integer where in reality, the maximum marks are In order to restrict access and to check data before it is assigned to the variables, we provided the get and set methods.

We haven't done such checking for the name variable. We shall see how it can be done for the marks1 variable. For this purpose, we use decision making statements. We shall see two of them for now: Following is the syntax of the if statement:What are the different methods of writing a set?

method in wrinting a set Share to: What are the two methods of describing or writing a set?

different methods of writing a set

There are way more than just 2 methods. 1. Write down the elements, works well for finite sets. e.g.{1, 2, 3, pi, apple} 2. Writing an academic essay means fashioning a coherent set of ideas into an argument.

Because essays are essentially linear—they offer one idea at a time—they must present their ideas in the order that makes most sense to a reader. Successfully structuring an essay means attending to a reader's logic. There are two ways of describing, or specifying the members of, a set. One way is by intensional definition, using a rule or semantic description: The second way is by exten sion - that is, listing each member of the set.

methods for describing quantitative data are illustrated in Sections , , and ; numerical descriptive methods for quantitative data are presented in Sections –We end this chapter with a section on the misuse of descriptive techniques.

Aug 31,  · These are the four different types of writing that are generally used. There are many sub-types of writing that may fall in any of those categories. A writer must know all these styles in order to identify the purpose of his or her own writing and make Reviews: Mastering these and other storytelling methods is the key to writing your own engaging tale.

Just as a lion is the product of all the zebras it has eaten, a writer is the product of all the books he or she has read.

How To Teach Writing: 6 Methods For Generating Writing Ideas