Assignment 2 Computational Coding
Assignment 2 Computational Coding
Assignment 2
Computational Coding with Java Standard
result = ~num1;
System.out.println("~num1 = " + result );
Code:-
Output:-
2) Write a code to demonstarte the uses of this keyword
public class this_keyword_usecases {
int x; // instance variable
// Constructor
this_keyword_usecases(int x) {
this.x = x; // using 'this' to refer to the instance variable
}
// Method
void display() {
System.out.println("Value of x: " + this.x); // using 'this' to refer to the instance
variable
}
// Inner class
class InnerClass {
void innerMethod() {
System.out.println("Value of x from inner class: " +this_keyword_usecases.this.x);
// using 'this' to refer to the outer class instance
}
}
Output:-
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING