C# · Chapter 3.6 · Intermediate level
Classes & Objects (OOP — Pokemon Battle Generator!)
Classes और Objects (OOP — पोकेमॉन बैटल जनरेटर!)
Now you unlock the superpower of big games — Object-Oriented Programming (OOP)! Imagine a cookie cutter or architectural blueprint:
• class Pokemon: The Blueprint (Naksha) saying every Pokemon has a name, power, and Attack() move.
• Pokemon p2 = new Pokemon();: Uses new to spawn a real living Object (Charizard, Power 120) from that blueprint! From one blueprint, you can spawn 100 different Pokemons!
अब सीखो बड़े गेम्स की सबसे बड़ी ताकत — OOP (Classes & Objects)! इसे घर के नक्शे और असली घर से समझो:
• class Pokemon: यह सिर्फ़ नक्शा (Blueprint) है जिसमें लिखा है कि हर पोकेमॉन का एक name, एक power, और Attack() होगा।
• Pokemon p2 = new Pokemon();: new शब्द नक्शे से एक असली पोकेमॉन कैरेक्टर (Object) पैदा कर देता है — जैसे Charizard जिसकी पावर 120 है!
Words and symbols in this chapter
class Pokemon { ... }- Blueprint defining what data (
name,power) and actions (Attack()) every Pokemon has. - पोकेमॉन का नक्शा जिसमें उसके गुण (
name,power) और एक्शन (Attack()) लिखे हैं। public string name;publicletsMain()read & set this Pokemon'sname.publicलिखने से हम बाहर से पोकेमॉन काnameसेट कर सकते हैं।new Pokemon()newkeyword constructs a brand-new Pokemon object in memory!newशब्द मेमोरी में नया असली पोकेमॉन ऑब्जेक्ट पैदा करता है!p2.name = "Charizard";- The dot
.means 'of' — sets thenameofp2to'Charizard'. - डॉट
.का मतलब है 'का' — यानीp2काnameबराबर'Charizard'। p2.Attack();- Commands
p2(Charizard) to unleash its fire attack! p2(Charizard) को अपना फ़ायर अटैक चलाने का आदेश देता है!
Ready example
using System;
class Pokemon {
public string name;
public int power;
public void Attack() {
Console.WriteLine(name + " used Fire Blast! Power: " + power);
}
}
class Program {
static void Main() {
Pokemon p2 = new Pokemon();
p2.name = "Charizard";
p2.power = 120;
p2.Attack();
}
}
What you will see: A glowing Holographic Battle Card for 🔥 Charizard (Power: 120) unleashes Fire Attack in the Game Arena!
गेम प्रिव्यू में 🔥 Charizard (Power: 120) का चमकता बैटल कार्ड और फ़ायर अटैक एनिमेशन चलेगा!
Line by line
class Pokemon { public string name; public int power; ... }- Defines the reusable
Pokemonblueprint. Pokemonका नक्शा (Class) तैयार किया।Pokemon p2 = new Pokemon();- Spawns object
p2from thePokemonclass. - नक्शे से असली ऑब्जेक्ट
p2बनाया। p2.name = "Charizard"; p2.power = 120;- Sets
p2's name to'Charizard'and power to120. p2का नाम'Charizard'और ताकत120रखी।p2.Attack();- Triggers Charizard's Holographic Battle Card & Fire Attack!
- Charizard का होलोग्राफिक बैटल कार्ड और फ़ायर अटैक चलाता है!
Common mistake
✗ Wrong
Pokemon p1 = Pokemon();✓ Right
Pokemon p1 = new Pokemon();In C#, you must write the new keyword to spawn an actual object from a class blueprint!
क्लास के नक्शे से असली ऑब्जेक्ट पैदा करने के लिए new शब्द लिखना ज़रूरी है (new Pokemon())!
Your task
Spawn Pokemon p2 = new Pokemon();, set p2.name = "Charizard";, p2.power = 120;, and call p2.Attack();!
Pokemon p2 = new Pokemon(); बनाओ, p2.name = "Charizard"; व p2.power = 120; रखो, और p2.Attack(); चलाओ!
- Keep the
class Pokemonblueprint at the top.
ऊपरclass Pokemonका नक्शा रहने दो। - Inside
Main(), writePokemon p2 = new Pokemon();.Main()मेंPokemon p2 = new Pokemon();लिखो। - Set
p2.name = "Charizard";,p2.power = 120;, and callp2.Attack();, then Run!p2.name = "Charizard";,p2.power = 120;औरp2.Attack();लिखकर Run दबाओ!
Starter code for the task
using System;
class Pokemon {
public string name;
public int power;
public void Attack() {
Console.WriteLine(name + " attacked with power " + power);
}
}
class Program {
static void Main() {
// TODO 1: Pokemon p2 = new Pokemon(); se naya object banao
// TODO 2: p2.name = "Charizard"; aur p2.power = 120; set karo
// TODO 3: p2.Attack(); call karo
}
}Do this task in the classroom: your code is checked automatically and you get hints if something is missing.
Recap
- A
classis a blueprint; an object is a real thing made withnew. Pokemon p2 = new Pokemon();creates an object;p2.name = "Charizard";sets its field.- Call an object’s method with a dot:
p2.Attack();.
classएक नक्शा है; objectnewसे बनी असली चीज़ है।Pokemon p2 = new Pokemon();object बनाता है;p2.name = "Charizard";उसका field सेट करता है।- Object का method बिंदु से बुलाओ:
p2.Attack();।
Quick quiz
Which keyword creates a live Object from a C# class blueprint?
C# में class नक्शे से असली Object बनाने के लिए कौन-सा कीवर्ड लगता है?
Show the answer
Answer: C (new)
Pokemon p1 = new Pokemon(); spawns a new object in memory!
new कीवर्ड क्लास से नया ऑब्जेक्ट तैयार करता है!
Practice problems for this chapter
- IPL Player Cards (class & object — fill the blanks)
IPL प्लेयर कार्ड (class और object — खाली जगह भरो)
Solve them in the Practice Zone, where each answer is checked automatically and two hints are available.