23ID01CE020 (Practical - 4)
23ID01CE020 (Practical - 4)
void display() {
System.out.println("title: " + title);
System.out.println("author: " + author);
System.out.println("price: " + price + "\n");
}
book1.display();
book1.display();
}
}
Output:-
2. Access Modifiers
Code:-
class Account {
private int accountNumber;
private String accountHolderName;
private int balance;
private String password;
account1.display("Exotic_Swap");
account1.depositing(25000, "Exotic_Swap");
account1.display("Herge");
account1.withdrawing(50000, "Exotic_Swap");
account1.display("Exotic_Swap");
}
}
3. Constructors
Code:-
class Student {
String name;
int age;
String course;
Student() {
name = "unknown";
age = 0;
course = "unknown";
}
Student(String name) {
this.name = name;
age = 0;
course = "unknown";
}
void display() {
System.out.println("name: " + name);
System.out.println("age: " + age);
System.out.println("course: " + course +
"\n");
}
}
resource1 = null;
resource2 = null;
resource3 = null;
System.gc();
}
}
Output:-
5. ‘this’ Keyword
Code:-
class Rectangle {
int calculateArea() {
return length * width;
}
rectangle1.setDimensions(5, 10);
rectangle2.setDimensions(10, 20);
rectangle1.compareArea(rectangle2);
}
}
Output:-
Counter() {
count++;
id = count;
}
void display() {
System.out.println("ID: " + id + " Count: " +
count);
}
}
c1.display();
c2.display();
Counter.resetCounter();
c3.display();
c4.display();
c5.display();
}
}
Output:-
7. ‘static’ Keyword
Code:-
class MathUtils {
static double PI;
static {
PI = 3.14159;
}
9. Wrapper Classes
Code:-
import java.util.Scanner;