JAVA is a Programming language like Core PHP. In this article, you will learn how to create classes or objects in JAVA. Example:- public class MyClass { int x = 10; public static void main(String[] args) { MyClass myObj1 = new MyClass(); MyClass myObj2 = new MyClass(); System.out.println(myObj1.x); System.out.println(myObj2.x); } } Read on Facebook
Condition Statements are the same we use in PHP but the syntax is different in JAVA. In this article, you will learn How to Create Condition Statements in JAVA Example:- public class MyClass { public static void main(String[] args) { int time = 22; if (time < 10) { System.out.println("Good morning."); } else if (time < […]
In this article, you will learn How to Create Switch Statement in JAVA with a break. It works like in C language or Core PHP. Example:- public class MyClass { public static void main(String[] args) { int day = 4; switch (day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; case […]
In this article, you will learn How to Create Constructors in JAVA. Example:- public class Car { int modelYear; String modelName; public Car(int year, String name) { modelYear = year; modelName = name; } public static void main(String[] args) { Car myCar = new Car(1969, "Mustang"); System.out.println(myCar.modelYear + " " + myCar.modelName); } } Read […]
In this article, you will learn How to Create Input using JAVA. It works like in HTML and PHP Example:- import java.util.Scanner; // import the Scanner class class MyClass { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); String userName; System.out.println("Enter username"); userName = myObj.nextLine(); System.out.println("Username is: " + userName); } } Read on Facebook
In this article, you will learn How to Create Inheritance in JAVA. Example:- class Vehicle { protected String brand = "Samsung"; public void honk() { System.out.println("Mobile, LED!"); } } class Car extends Vehicle { private String modelName = "Galaxy"; public static void main(String[] args) { Car myFastCar = new Car(); myFastCar.honk(); System.out.println(myFastCar.brand + " " […]
In this article, you will learn How to Create Polymorphism in JAVA. Example:- class Animal { public void animalSound() { System.out.println("The animal makes a sound"); } } class Pig extends Animal { public void animalSound() { System.out.println("The pig says: wee wee"); } } class Dog extends Animal { public void animalSound() { System.out.println("The dog says: […]