Posts

Showing posts with the label local variables

Datatype and keyword

Image
Like any programming language, C# defines keywords for fundamental data types, which are used to represent local variables, class data member variables, method return values, and parameters. Unlike other programming languages, however, these keywords are much more than simple compiler- recognized tokens. Rather, the C# data type keywords are actually shorthand notations for full-blown types in the System namespace. Table lists each system data type, its range, the corresponding C# keyword, and the type’s compliance with the common language specification (CLS). C# keyword System type Range Meaning CLS complaint? bool System.Boolean true or false Represents truth or falsity Yes sbyte System.SByte -128 to 127 signed 8-bit number No byte System.Byte 0 to 255 Unsigned 8-bit ...

Method in Java

Image
Methods appear inside class bodies. They contain local variable declarations and other Java statements that are executed when the method is invoked. Methods may return a value to the caller. They always specify a return type, which can be a primitive type, a reference type, or the type void , which indicates no returned value. Methods may take arguments, which are values supplied by the caller of the method. Lets see example: Program class multiply { int num1; int num2; int mul(int x,int y) { int result; num1 = x; num2 = y; result = num1*num2; return result; } } public class Main { public static void main (String[] args) { multiply m = new multiply(); System.out.println("multiplication of 3 and 5 is " + m.mul(3,5)); } } Run Output multiplication of 3 and 5 is 15 Explanation In this example, the class multiply defines a method, mul() , that takes as argu...