Week 02 Programming Assignment
Week 02 Programming Assignment
4)
ANS: The Program which shows the use of local, instance and static
variables :
5)
ANS: Instance Variable is used when every variable has a different value
for different object. E.g. name of student, roll number etc and Static
Variable is used when the value of the variable is independent of the
objects (not unique for each object). E.g. number of students.
6)
ANS : The PROGRAM which tries to print an instance variable directly in a
static method is:
ERROR :
8)
ANS : Declaration of a local variable inside the main method with no
initialization ;
ERROR :
= The error that we'll encounter while executing this program is a
compilation error. It's a "variable might not have been initialized" error. The
Java compiler doesn't allow us to use a local variable without initializing it
first. In this case, we are trying to print the value of x before giving it any
initial value, which is not allowed in Java.
To resolve this error, we should initialize the local variable x with a value
before trying to use it.
We must initialize the variable in java in order to compile it, otherwise there
will be error.
9)
ANS : The program to print the area of a rectangle using the concept of
variables is give below :
RESULT :
10)
ANS : SUMMARY OF WEEK -2 ;
POINTS TO REMEMBER :
1. Identifiers consists of letters, digits and two only characters '_' and '$‘
2. Identifiers cannot start with digits and should not contain spaces.
3. Reserved keywords are not allowed for declaring identifiers.
4. A variable declared in method block of main method, can only be
used inside the method block of main method and It cannot be used
in another method block of m1 method.
5. Local Variable is a variable which is declared inside the method or
method block.
6. Instance Variable is a variable declared inside the class but outside
the method or method block.
7. Static Varibale is a variable that is declared with the keyword static
and declared inside the class but outside of method or method block.
8. Operators are certain symbols that tell the Java compiler to perform
an operation.
9. Operands are the variables that are used to store the values.
10. Arithmetic Operators are operators used in mathematical
calculations.
11. Relational Operators are Used to determine the relationship that
one operand has with another.
12. Assignment Operators Used to assign a new value to the variable.
13. Conditional Operator is also known as ternary operator which is
applicable for 3 operands.
14. Bitwise Operator Used to work with variables at bit level.
15. Logical Operator combines 2 Boolean values and the output is
also Boolean.
-THE END-