জাভা প্রোগ্রামিং লেনগুয়েজ হাতেখড়ি-তৃতীয় পর্ব

class কি?

class হল ইউজার-ডিফাইনড বা ব্যবহারকারী নির্ধারিত ডেটা টাইপ, যা প্রোগ্রামে বিল্ট   ইন ডেটা  টাইপের  মত কাজ করে। এটি class এ বিল্ট ইন ডেটা টাইপের কয়েকটি ভেরিয়েবল এবং ঐ ভেরিয়েবল  এক্সেস  করার জন্য কতগুলো ফাংশন থাকে। প্রয়োজন অনুসারে প্রোগ্রামে class বর্ননা করা হয়।

প্রকৃত বিশ্বে, আপনি একই ধরনের অনেক স্বতন্ত্র বস্তু সামজস্য খুঁজে পাবেন। bicyclesএর হাজার হাজার একই রকম তৈরি করা এবং একই মডেলের প্রত্যেক bicycle blueprintsএর একই সেট থেকে নির্মাণ করা হয়েছিল.এবং একই উপাদান দিয়ে। object-oriented শর্তাবলীতে, আমরা জানি  যে আপনার bicycle ,bicycles হিসেবে একই শ্রেনীর । একটি শ্রেনী থেকে blueprint যেটি স্বতন্ত্র বস্তু তৈরি করা হয়। এখানে বলা হয়েছে যে  প্রথমে একটি bicycle তৈরী করে পরবতিতে তা থেকে অনেক গুলো সাইকেল তৈরী করা হয়।  **লেখকের (এম ইয়াকুব)অনুমতি ব্যতিরেকে এই লেখার  আংশিক বা পূর্ণ অংশ কোন ধরনের মিডিয়ায় পুনঃপ্রকাশ করা যাবে না।

জাভায় class ঘোষনার জন্য class keyword র পর ঐ class এর নাম দিতে হয়। class বডিতে class এর মেম্বার ভেরিয়েবলগুলোর ঘোষনা এবং মেম্বার ফাংশনগুলোর বর্ননা থাকে।

নিম্নলিখিত  উদাহরনটি লক্ষ্য করুন এখানে class হল Bicycle :

Bicycle class is one possible implementation of a bicycle:

class Bicycle {

int cadence = 0;
int speed = 0;
int gear = 1;

void changeCadence(int newValue) {
cadence = newValue;
}

void changeGear(int newValue) {
gear = newValue;
}

void speedUp(int increment) {
speed = speed + increment;
}

void applyBrakes(int decrement) {
speed = speed - decrement;
}

void printStates() {
System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear);
}
}

The syntax of the Java programming language আপনাকে নতুন করে দেখবে, but the design of this class is based on the previous discussion of bicycle objects. The fields cadence, speed, and gear represent the object's state, and the methods (changeCadence, changeGear, speedUp etc.)

একটি bicycle এর জন্য blueprint মাত্র  একটি,  একটি অ্যাপলিকেশনে but the design of this class is based on the ব্যবহার করা যাবে।

এখানে একটি Bicycle class যা দুইটি আলাদা Bicycle objects and invokes their methods:

class Bicycle {
public static void main(String[] args) {

// Create two different Bicycle objects
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();

// Invoke methods on those objects
bike1.changeCadence(50);
bike1.speedUp(10);
bike1.changeGear(2);
bike1.printStates();

bike2.changeCadence(50);
bike2.speedUp(10);
bike2.changeGear(2);
bike2.changeCadence(40);
bike2.speedUp(10);
bike2.changeGear(3);
bike2.printStates();
}
}

নিম্নে  output দেখুন  the ending pedal cadence, speed, and gear for the two bicycles:

cadence:50 speed:10 gear:2
cadence:40 speed:20 gear:3

চলবে...............

Level 3

আমি মোহাম্মদ ইয়াকুব। বিশ্বের সর্ববৃহৎ বিজ্ঞান ও প্রযুক্তির সৌশল নেটওয়ার্ক - টেকটিউনস এ আমি 14 বছর 4 মাস যাবৎ যুক্ত আছি। টেকটিউনস আমি এ পর্যন্ত 42 টি টিউন ও 322 টি টিউমেন্ট করেছি। টেকটিউনসে আমার 6 ফলোয়ার আছে এবং আমি টেকটিউনসে 16 টিউনারকে ফলো করি।

ICT Specialist & IT Business Entrepreneurship, Course Curriculum expert, eLearning, Education & Industry Partnership expert. Expertise in Cyber Security, Cloud Computing, AI, Big Data, RFID, Technology Project Management, Change management, leadership & the development of comprehensive large scale eHealth programs. Former Asset Professor in University of Kuala Lumpur, Kuala Lumpur,...


টিউনস


আরও টিউনস


টিউনারের আরও টিউনস


টিউমেন্টস

ভাল টিউনস।

Level 0

ভাই দয়া করে বলবেন কিভাবে .class ফাইল সম্পাদনা ও সংরক্ষণ করব।

Level 0

চালায়ে যান ওস্তাদ..চালায়ে যান…

Level 0

ওস্তাদ ধইরেছেন যখন শেষ দেখাইয়া ছাইড়েন..JAVA গেমস/ই বুক/এপ্লিকেশন কোনটাই বাদ দিয়েন না ।