We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bbbd2a8 commit d546a2bCopy full SHA for d546a2b
Reference _Variable_Casting.java
@@ -0,0 +1,30 @@
1
+package main;
2
+/*
3
+@author:Akash Tiwari
4
+*/
5
+
6
+ class A{
7
8
+}
9
+ class B extends A{
10
11
+ }
12
+public class consrtuct {
13
14
+ public static void main(String[] args) {
15
+ A a=new A();
16
+ B b=new B();
17
+ // b=a; //Type mismatch: cannot convert from A to B
18
19
+ //But this can also be overcome by making the behaviour of A to be as B.
20
+ a=b; //line20
21
+ b=(B)a; //This will not cause any compilation error
22
+ /*
23
+ The order of line 20 and 21 is importent as it first make
24
+ a polymorphic polymorphism is made so that the next line make itself as pure polymorphism
25
+ else it gives classCastException runtime error
26
+ */
27
+ System.out.println("Success");
28
29
30
0 commit comments