. Arithmetic Operations using Command [Link].
println("Value of static variable j
1
Line Arguments is " + j);
class Arithmetic { }
public static void main(String[] args) { int a =}
[Link](args[0]); int b = class TestStatic {
[Link](args[1]); public static void main(String args[]) {
[Link]("Add: " + (a + b)); [Link]();
[Link]("Sub: " + (a - b)); }
[Link]("Mul: " + (a * b)); }
[Link]("Div: " + (a / b)); } 4. 2-D Jagged Array
} public class JaggedArrayDemo { public
2. Instance Variables and Methods (Studentstatic void main(String[] args) { int[][] marks
Details) = new int[3][];
class Student { marks[0] = new int[3];
int rollNo; marks[1] = new int[2];
String name; marks[2] = new int[4];
String course; marks[0][0] = 85;
double marks; marks[0][1] = 90;
void setDetails(int r, String n, String c, marks[0][2] = 88;
double m) { marks[1][0] = 75;
rollNo = r; marks[1][1] = 80;
name = n; marks[2][0] = 92;
course = c; marks[2][1] = 89;
marks = m; marks[2][2] = 94;
} marks[2][3] = 91;
void displayDetails() { for (int i = 0; i < [Link]; i++) {
[Link]("Roll No: " + rollNo); [Link]("Student " + (i + 1) + "
[Link]("Name: " + name); Marks:");
[Link]("Course: " + course); for (int j = 0; j < marks[i].length; j++) {
[Link]("Marks: " + marks); } [Link](marks[i][j] + " "); }
} }
public class CollegeSystem { }
public static void main(String[] args) { }
Student s1 = new Student(); 5. Constructor Overloading
Student s2 = new Student(); class Student {
[Link](1, "Kritin", "CSE", 88.5); int rollNo;
[Link](2, "Rishi", "ECE", 76.0); String name;
[Link](); Student() {
[Link](); rollNo = 0;
} name = "Default";
} }
3. Static Variable and Static Method Student(int r, String n) {
class StaticMethod { rollNo = r;
static int j = 0; name = n;
static void getVariable() { }
j++; void display() {
[Link](rollNo + " " + name); } class Addition {
S
} void sum(int a, int b) {
class Demo { [Link]("Result is " + (a + b));
public static void main(String[] args) { }
Student s1 = new Student(); float sum(float a, float b) {
Student s2 = new Student(101, "Ram"); return (a + b);
[Link](); }
[Link](); double sum(double a, double b) { return (a
} + b);
} }
6. Method Overriding (Payment System) }
class Payment { public class OverloadMethod {
void pay() { public static void main(String[] args) {
[Link]("Processing payment...");Addition a1 = new Addition();
} [Link](3, 4);
} float x = [Link](3.4f, 4.5f);
class CreditCard extends Payment { void [Link]("Sum of floating point
pay() { numbers " + x);
[Link]("Payment done using double y = [Link](3.45, 4.56);
Credit Card"); [Link]("Sum of double numbers
} " + y);
} }
class UPI extends Payment { }
void pay() { 8. Single Level Inheritance
[Link]("Payment done using class Employee {
UPI"); int id;
} void setId(int i) {
} id = i;
class NetBanking extends Payment { void }
pay() { }
[Link]("Payment done using class Manager extends Employee { void
Net Banking"); display() {
} [Link]("Employee ID: " + id); }
} }
class Demo { class Demo {
public static void main(String[] args) { public static void main(String[] args) {
Payment p; Manager m = new Manager();
p = new CreditCard(); [Link](101);
[Link](); [Link]();
p = new UPI(); }
[Link](); }
p = new NetBanking(); 9. Multi-Level Inheritance
[Link](); class Person {
} String name;
} void setName(String n) {
7. Method Overloading name = n;
} [Link]();
} Bus bs = new Bus();
class Employee extends Person { int empId;[Link]();
void setEmpId(int id) { [Link]();
empId = id; }
} }
} 11. Super Constructor
class Manager extends Employee { void class Person {
display() { String name;
[Link]("Name: " + name); int id;
[Link]("Employee ID: " + Person(String n, int i) {
empId); name = n;
} id = i;
} }
class Demo { }
public static void main(String[] args) { class Employee extends Person {
Manager m = new Manager(); double salary;
[Link]("Krishna"); Employee(String n, int i, double s) { super(n,
[Link](101); i);
[Link](); salary = s;
} }
} void display() {
10. Hierarchical Inheritance [Link]("Name: " + name);
class Vehicle { [Link]("ID: " + id);
void start() { [Link]("Salary: " + salary); }
[Link]("Vehicle is starting"); } }
} class Demo {
class Car extends Vehicle { public static void main(String[] args) {
void showCar() { Employee e = new Employee("Arav", 101,
[Link]("This is a Car"); } 50000);
} [Link]();
class Bike extends Vehicle { void }
showBike() { }
[Link]("This is a Bike"); } 12. Abstract Class
} abstract class Shape {
class Bus extends Vehicle { abstract void draw();
void showBus() { }
[Link]("This is a Bus"); } class Circle extends Shape {
} void draw() {
class Demo { [Link]("Drawing Circle"); }
public static void main(String[] args) { Car c }
= new Car(); c
lass Rectangle extends Shape { void
[Link](); draw() {
[Link](); [Link]("Drawing Rectangle"); }
Bike b = new Bike(); }
[Link](); class Demo {
ublic static void main(String[] args) {
p }
Shape s; class Customer implementsBank { void
s = new Circle(); showLimit() {
[Link](); [Link]("Maximum Limit: " +
s = new Rectangle(); MAX_LIMIT);
[Link](); }
} }
} class Demo {
13. Abstract Methods (ATM System) public static void main(String[] args) {
abstract class ATM { Customer c = new Customer();
abstract void withdraw(double amount); [Link]();
abstract void deposit(double amount); } }
class SBI extends ATM { }
void withdraw(double amount) { 15. Interface Inheritance
[Link]("SBI Withdraw: " + interface A {
amount); void showA();
} }
void deposit(double amount) { interface B extends A {
[Link]("SBI Deposit: " + void showB();
amount); }
} class Demo implements B {
} public void showA() {
class HDFC extends ATM { [Link]("Method from Interface
void withdraw(double amount) { A");
[Link]("HDFC Withdraw: " + }
amount); public void showB() {
} [Link]("Method from Interface
void deposit(double amount) { B");
[Link]("HDFC Deposit: " + }
amount); public static void main(String[] args) { Demo
} d = new Demo();
} [Link]();
class Demo { [Link]();
public static void main(String[] args) { ATM }
a; }
a = new SBI();
[Link](1000);
[Link](500);
a = new HDFC();
[Link](2000);
[Link](1000);
}
}
14. Variables in Interfaces
interface Bank {
int MAX_LIMIT = 50000;