আপকাস্টিং (Upcasting) কাকে বলে?
আপকাস্টিং মানে চাইল্ড ক্লাস থেকে একজন অভিভাবক তৈরি করা।
লিংকঃ http://tpcg.io/_NZTI1C
//জাভা (Java) – Upcasting
class Vehicle {
void printType() {
System.out.println(“This is a vehicle”);
}
}
class Car extends Vehicle {
void printModel(String m) {
System.out.println(“The model of the car is ” + m);
}
}
public class UpcastingExample {
public static void display(Vehicle v) {
v.printType();
}
public static void main(String[] args) {
Car c = new Car();
display(c);
c.printModel(“Honda”);
}
}
Output:
//জাভা (Java) – Output This is a vehicle The model of the car is Honda
লিংকঃ https://dotnetfiddle.net/M8YS8f
//সি# (C#)
using System;
public class Vehicle
{
public void PrintType()
{
Console.WriteLine(“This is a vehicle”);
}
}
public class Car : Vehicle
{
public void PrintModel(string m)
{
Console.WriteLine(“The model of the car is ” + m);
}
}
public class UpcastingExample
{
public static void Display(Vehicle v)
{
v.PrintType();
}
public static void Main(string[] args)
{
Car c = new Car();
Display(c);
c.PrintModel(“Honda”);
}
}