Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java instance of a class

// instanceof can be used to check whether an object
// is an instance of a given class or not, as illustrated below
public class Main {
	public static void main(String[] args) {
		String str = new String("Foo");
		System.out.println( str instanceof String); // true
		Shape s = new Triangle();
      	// s is instance of parent class Shape
		System.out.println(s instanceof Shape); // true
      	// s is also instance of child class called Triangle
		System.out.println(s instanceof Triangle); // true

	}
}
class Shape {
	public void draw() {
		System.out.println("Shape draw.");
	}
}
class Triangle extends Shape {
	public void draw() {
		System.out.println("Triangle draw.");
	}
}
Comment

create new instance of class java

class_name object_name = new class_name();
Comment

PREVIOUS NEXT
Code Example
Java :: max and min array number in java 
Java :: spring filter exception handling 
Java :: java printf 
Java :: java repository sql find not in list 
Java :: java printf tab 
Java :: how to set boolean to false if null java 
Java :: has been compiled by a more recent version of the Java Runtime (class file version ), this version of the Java Runtime only recognizes class file versions up to 
Java :: java.lang.ArrayIndexOutOfBoundsException 
Java :: throw error java 
Java :: how to find palindrome numbers in java 
Java :: Java char data type 
Java :: linkedhashmap in java 
Java :: how to reverse a number in java 
Java :: how to display the decimal value when 0 after point android studio 
Java :: java multiple catch blocks 
Java :: Java program to print decimal to octal conversion 
Java :: how to count the number of occurrences of an element in a arraylist in java 
Java :: apache csv get headers 
Java :: How to get the nth Fibonacci number code in Java using recursion 
Java :: how to get string from resource id android 
Java :: java to the power of 
Java :: tostring in java 
Java :: java convert am pm to 24 hour 
Java :: how to get request json web token in next js 
Java :: infinite for loop java example 
Java :: $JAVA_HOME ENV 
Java :: vscode code formatter cannot format 
Java :: set jcombobox index java 
Java :: latest android sdk version 
Java :: Compare integers java sort 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =