public class Person {
String name;
int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public void displayInfo() {
System.out.println(name + " is " + age + " years old.");
}
public static void main(String[] args) {
Person person;
person. age=20;
person.displayInfo();
}
}❤1
public class Person {
String name;
int age;
Person (int y, String a){
age=y;
name=a;
}
public void displayInfo() {
System.out.println(name + " is " + age + " years old.");
}
public static void main(String[] args) {
Person person=new Person(20,"M");
Person p;
p=person;
p.displayInfo();
}
}👍4❤2
polymorphism in java is a concept by which we can perform a single action in different ways
Anonymous Quiz
86%
✅
14%
❌❌
the most common use of polymorphism in oop occurs when a parent class reference is used to refer a child class object
Anonymous Quiz
54%
upcasting
13%
Downcasting
14%
polymorphism
19%
A&&C
there are two types of polymorphism in java is
Anonymous Quiz
24%
override && overlloding
6%
upcasting&& Downcasting
38%
compile time polymorphism&&runtime polymorphism
32%
A&B
تجمع شيتات واسئلة oop
there are two types of polymorphism in java is
الجواب مفروضA&&C
a process of converting one data type to another is known as Typercasting
sub class object type has been converted into super class type rhi is kind of conversion
Anonymous Quiz
25%
upcasting
35%
Downcasting
4%
widenning
36%
A&C
if we perform it directly java compiler wilk give compile time error
Anonymous Quiz
37%
upcasting
63%
Downcasting
class One {
// طريقة m1
public void m1() {
System.out.println("m1 method in class One");
}
}
// الفئة الفرعية Two التي تمتد من One
class Two extends One {
// طريقة m2
public void m2() {
System.out.println("m2 method in class Two");
}
}
// الفئة Test تحتوي على دالة main
public class Test {
public static void main(String[] args){
One N=new One ();
Two t = (Tow) N ;
//t.m1();
t.m2();
}
}
تجمع شيتات واسئلة oop
الupcasting توصل في دوال الاب فقط الا اذا كان فيه override والا هيصير كومبايلر تايم ايرور
وDowncasting توصل في دوال كلهن الاب والابن
❤3
method is overriden not the datamembers so runtime polymorphism cannot be achieved by data members
Anonymous Quiz
42%
✅
58%
✅✅