Premium Only Content

#22 Class and Object Practical in JAVA | Skyhighes | Lecture 22
Here's a practical demonstration of classes and objects in Java:
1. Create a Class:
Java
public class Calculator {
int num1;
int num2;
public int add() {
return num1 + num2;
}
public int subtract() {
return num1 - num2;
}
}
Use code with caution. Learn more
2. Create Objects of the Class:
Java
Calculator calc1 = new Calculator();
Calculator calc2 = new Calculator();
Use code with caution. Learn more
3. Access and Modify Object Attributes:
Java
calc1.num1 = 10;
calc1.num2 = 5;
calc2.num1 = 20;
calc2.num2 = 8;
Use code with caution. Learn more
4. Call Object Methods:
Java
int result1 = calc1.add(); // result1 will be 15
int result2 = calc2.subtract(); // result2 will be 12
System.out.println("Result of addition: " + result1);
System.out.println("Result of subtraction: " + result2);
Use code with caution. Learn more
Output:
Result of addition: 15
Result of subtraction: 12
Key Points:
Each object has its own distinct values for attributes (num1 and num2).
Methods (add() and subtract()) operate on the object's specific data.
Multiple objects of the same class can exist independently.
Additional Examples:
Create a Person class with attributes like name, age, and address, and methods like greet() and introduce().
Create a BankAccount class with attributes like accountNumber, balance, and methods like deposit(), withdraw(), and checkBalance().
Create a Car class with attributes like make, model, color, and methods like start(), stop(), and accelerate().
Experiment with different classes and objects to solidify your understanding of these fundamental OOP concepts in Java!
-
54:12
Donald Trump Jr.
3 hours agoCharlie's Vision. Our Future. | TRIGGERED Ep274
143K103 -
1:03:35
BonginoReport
4 hours agoKirk’s Alleged Killer Dating Hateful Transgender??? - Nightly Scroll w/ Hayley Caronia (Ep.134)
80.4K99 -
1:01:12
The Nick DiPaolo Show Channel
6 hours agoKirk Assassination Exposes Insane Left | The Nick Di Paolo Show #1793
50.7K19 -
1:48:38
The Mike Schwartz Show
4 hours agoTHE MIKE SCHWARTZ SHOW Evening Edition 09-15-2025
24.1K11 -
LIVE
LIVE WITH CHRIS'WORLD
6 hours agoLIVE WITH CHRIS'WORLD - They Just Created 1 Million Charlie Kirks
96 watching -
DVR
Quite Frankly
7 hours agoStaggering Evil, Official Stories & Open Lines | Rich Baris 9/15/25
22.7K5 -
1:09:33
TheCrucible
5 hours agoThe Extravaganza! EP: 36 (9/15/25)
166K18 -
1:13:06
Candace Show Podcast
4 hours agoThey Are Lying About Charlie Kirk. | Candace Ep 235
101K475 -
1:47:40
Kim Iversen
5 hours agoWas There a Second Shooter in the Charlie Kirk Attack?
56.7K95 -
2:38:10
Redacted News
5 hours ago“They’re NOT stopping with Charlie Kirk!” JD Vance TORCHES violent leftists | Redacted
242K126