ISC Grade 11 Java Notes
ISC Grade 11 Java Notes
Features of Objects:
- Identity: Unique reference (like memory address).
Attributes in a Class:
Attributes are instance variables defined inside the class but outside methods.
class Student {
int rollNumber; // attribute
String name; // attribute
}
Methods in a Class:
class Student {
int rollNumber;
String name;
void display() {
System.out.println("Roll: " + rollNumber + ", Name: " + name);
}
}
Constructors:
Constructors initialize objects. They have the same name as the class and no return type.
class Student {
int rollNumber;
String name;
Student(int r, String n) {
rollNumber = r;
name = n;
}
void display() {
System.out.println("Roll: " + rollNumber + ", Name: " + name);
}
}
Type Casting:
int a = 10;
double b = a; // Widening
int c = (int) 5.67; // Narrowing
int x = 10, y = 5;
int sum = x + y;
Selection Statements:
Iteration Statements:
// for loop
for (int i = 1; i <= 5; i++) {
System.out.println(i);
}
// while loop
int j = 1;
while (j <= 5) {
System.out.println(j);
j++;
}
// do..while loop
int k = 1;
do {
System.out.println(k);
k++;
} while (k <= 5);
Jump Statements:
5. Functions/Methods
Call by Value:
void change(int x) {
x = 100;
}
void modify(Student s) {
s.name = "Updated";
}
Static Members:
class Counter {
static int count = 0;
Counter() {
count++;
}
int count = 0;
void increment() {
count++;
}