We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7bac0dc commit 7039c8cCopy full SHA for 7039c8c
Object Oriented Programming/InstanceOfKeyword.java
@@ -0,0 +1,14 @@
1
+// Author: Atharv Damle
2
+// Code to demonstrate use of instanceof keyword.
3
+// Full Question: https://www.hackerrank.com/challenges/java-instanceof-keyword/problem
4
+
5
+// a instanceof b checks if 'a' is a subclass of 'b'. Returns true if yes otherwise false.
6
+// Since the instance of any class is inherited from Java Object, element acts as a sort of generic data type
7
+// which can be instanciated by any class.
8
+Object element=mylist.get(i);
9
+if(element instanceof Student)
10
+ a++;
11
+else if(element instanceof Rockstar)
12
+ b++;
13
+else if(element instanceof Hacker)
14
+ c++;
0 commit comments