21 Apr, 2022
জাভার অবস্ট্রাক্শনের সমস্ত বিষয় নিয়ে আলোচনা করা হলো :
Abstraction : Abstraction is nothing but hiding the essential information and highlight the only set of services.
১.অ্যাবস্ট্রাক্ট মেথডের কোনো বডি হয় না।
২.কোনো ক্লাসে একটিমাত্র অ্যাবস্ট্রাক্ট মেথড থাকলেই ঐ ক্লাসটি অ্যাবস্ট্রাক্ট হয়ে যায়।
package customar;
import java.util.Scanner;
abstract class Bank
{
public String Name="WorldBank";
public String IFSC_No="WorldBank999";
public void bankdetails()
{
System.out.println("Our bank name is "+Name+"and IFSC code
:"+IFSC_No);
}
abstract void deposite();
abstract void withdraw();
abstract void chackbal();
}
class bankservice extends Bank
{
private int bal=5000;
private int pwd;
public int money;
@Override
public void deposite()
{
System.out.println("Enter password ");
Scanner s=new Scanner(System.in);
pwd=s.nextInt();
if(pwd==456)
{
System.out.println("Enter Deposite amount");
Scanner a=new Scanner(System.in);
money=a.nextInt();
bal=bal+money;
System.out.println("Deposite amount"+money);
System.out.println("Total amount"+bal);
}
else
{
System.out.println("Wrong password");
}
}
@Override
public void withdraw()
{
System.out.println("Enter password ");
Scanner s=new Scanner(System.in);
pwd=s.nextInt();
if(pwd==456)
{
System.out.println("Enter Deposite amount");
Scanner a=new Scanner(System.in);
money=a.nextInt();
bal=bal-money;
System.out.println("Deposite amount"+money);
System.out.println("Total amount"+bal);
}
else
{
System.out.println("Wrong password");
}
}
@Override
public void chackbal()
{
System.out.println("Enter password ");
Scanner s=new Scanner(System.in);
pwd=s.nextInt();
if(pwd==456)
{
System.out.println("Total amount"+bal);
}
else
{
System.out.println("Wrong password");
}
}
}
public class Customar {
public static void main(String[] args) {
bankservice b=new bankservice();
b.bankdetails();
int ch;
System.out.println("1.Deposite");
System.out.println("2.Withdraw");
System.out.println("3.Chack balance");
Scanner s3=new Scanner(System.in);
ch=s3.nextInt();
switch(ch)
{
case 1: b.deposite();
break;
case 2: b.withdraw();
break;
case 3: b.chackbal();
break;
default:
{
System.out.println("Wrong choice");
}
}
}
}
abstract class animal
{
void eys()
{
System.out.println("It have Two Eys");
}
abstract void sound();
abstract void eat();
}
class cat extends animal
{
@Override
void sound()
{
System.out.println("mew mew mew");
}
@Override
void eat()
{
System.out.println("Milk");
}
}
class tiger extends animal
{
@Override
void sound()
{
System.out.println("yaaw yaaw");
}
@Override
void eat()
{
System.out.println("Meat");
}
}
public class Zoo {
public static void main(String[] args) {
cat c=new cat();
tiger t=new tiger();
c.eat();c.eys();c.sound();
t.eat();t.eys();t.sound();
}
}
পাবলিক : ভ্যারিয়েবলটি যেকোনো জায়গা থেকে ব্যবহার করা যায়।
স্ট্যাটিক : ভ্যারিয়েবলটি অবজেক্ট ছাড়া রান হয়।
ফাইনাল : ভ্যারিয়েবলের মান পরিবর্তন করা যাবে না কখনও।
package javaapplication18;
interface car {
String Name= "BMW"; //Public + Static + Final
int Speed =120; //Public + Static + Final
abstract void start(); //Public + abstract
abstract void stop(); //Public + abstract
//jdk 1.8 you can implement defult
default void color() //public but not abstract
{
System.out.println("Black");
}
//jdk 1.8 you can implement Static
static void car_metal()
{
System.out.println("iron");
}
}
public class JavaApplication18 implements car {
// prove variable are public // anywere access
@Override
public void start()
{
System.out.println("Insart key");
// prove variable are public // anywere access
System.out.println(Name);
// prove variable are Static // access without object
System.out.println(Speed);
// prove variable are Final // No change
// Name= "Tosiba";
}
@Override
public void stop()
{
System.out.println("Remove key");
}
public static void main(String[] args)
{
JavaApplication18 c=new JavaApplication18();
c.start();
c.stop();
//jdk 1.8 you can implement defult
c.color();
// prove variable are Static // access without object
System.out.println(Speed);
//jdk 1.8 you can implement Static//call without object
car.car_metal();
}
}