Java Articles

Page 115 of 450

Prime number program in Java.

V Jyothi
V Jyothi
Updated on 11-Mar-2026 2K+ Views

Following is the required program.Examplepublic class Tester {    public static void main(String args[]) {       int i, m = 0, flag = 0;       int n = 41;// it is the number to be checked       m = n / 2;       if (n == 0 || n == 1) {          System.out.println(n + " not a prime number");       } else {          for (i = 2; i

Read More

Prime number program in Java.

V Jyothi
V Jyothi
Updated on 11-Mar-2026 2K+ Views

Following is the required program.Examplepublic class Tester {    public static void main(String args[]) {       int i, m = 0, flag = 0;       int n = 41;// it is the number to be checked       m = n / 2;       if (n == 0 || n == 1) {          System.out.println(n + " not a prime number");       } else {          for (i = 2; i

Read More

Factorial program in Java without using recursion.

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 2K+ Views

Following is the required program.Examplepublic class Tester {    static int factorial(int n) {       if (n == 0)          return 1;       else          return (n * factorial(n - 1));    }    public static void main(String args[]) {       int i, fact = 1;       int number = 5;       fact = factorial(number);       System.out.println(number + "! = " + fact);    } }Output5! = 120

Read More

Factorial program in Java without using recursion.

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 2K+ Views

Following is the required program.Examplepublic class Tester {    static int factorial(int n) {       if (n == 0)          return 1;       else          return (n * factorial(n - 1));    }    public static void main(String args[]) {       int i, fact = 1;       int number = 5;       fact = factorial(number);       System.out.println(number + "! = " + fact);    } }Output5! = 120

Read More

Single level inheritance in Java

Ramu Prasad
Ramu Prasad
Updated on 11-Mar-2026 15K+ Views

Single Level inheritance - A class inherits properties from a single class. For example, Class B inherits Class A.Exampleclass Shape {    public void display() {       System.out.println("Inside display");    } } class Rectangle extends Shape {    public void area() {       System.out.println("Inside area");    } } public class Tester {    public static void main(String[] arguments) {       Rectangle rect = new Rectangle();       rect.display();       rect.area();    } }OutputInside display Inside areaHere Rectangle class inherits Shape class and can execute two methods, display() and area() as shown.

Read More

Single level inheritance in Java

Ramu Prasad
Ramu Prasad
Updated on 11-Mar-2026 15K+ Views

Single Level inheritance - A class inherits properties from a single class. For example, Class B inherits Class A.Exampleclass Shape {    public void display() {       System.out.println("Inside display");    } } class Rectangle extends Shape {    public void area() {       System.out.println("Inside area");    } } public class Tester {    public static void main(String[] arguments) {       Rectangle rect = new Rectangle();       rect.display();       rect.area();    } }OutputInside display Inside areaHere Rectangle class inherits Shape class and can execute two methods, display() and area() as shown.

Read More

Single level inheritance in Java

Ramu Prasad
Ramu Prasad
Updated on 11-Mar-2026 15K+ Views

Single Level inheritance - A class inherits properties from a single class. For example, Class B inherits Class A.Exampleclass Shape {    public void display() {       System.out.println("Inside display");    } } class Rectangle extends Shape {    public void area() {       System.out.println("Inside area");    } } public class Tester {    public static void main(String[] arguments) {       Rectangle rect = new Rectangle();       rect.display();       rect.area();    } }OutputInside display Inside areaHere Rectangle class inherits Shape class and can execute two methods, display() and area() as shown.

Read More

Runtime Polymorphism in Java

Priya Pallavi
Priya Pallavi
Updated on 11-Mar-2026 19K+ Views

Method overriding is an example of runtime polymorphism. In method overriding, a subclass overrides a method with the same signature as that of in its superclass. During compile time, the check is made on the reference type. However, in the runtime, JVM figures out the object type and would run the method that belongs to that particular object.ExampleSee the example below to understand the concept −class Animal {    public void move() {       System.out.println("Animals can move");    } } class Dog extends Animal {    public void move() {       System.out.println("Dogs can walk and run"); ...

Read More

Runtime Polymorphism in Java

Priya Pallavi
Priya Pallavi
Updated on 11-Mar-2026 19K+ Views

Method overriding is an example of runtime polymorphism. In method overriding, a subclass overrides a method with the same signature as that of in its superclass. During compile time, the check is made on the reference type. However, in the runtime, JVM figures out the object type and would run the method that belongs to that particular object.ExampleSee the example below to understand the concept −class Animal {    public void move() {       System.out.println("Animals can move");    } } class Dog extends Animal {    public void move() {       System.out.println("Dogs can walk and run"); ...

Read More

Runtime Polymorphism in Java

Priya Pallavi
Priya Pallavi
Updated on 11-Mar-2026 19K+ Views

Method overriding is an example of runtime polymorphism. In method overriding, a subclass overrides a method with the same signature as that of in its superclass. During compile time, the check is made on the reference type. However, in the runtime, JVM figures out the object type and would run the method that belongs to that particular object.ExampleSee the example below to understand the concept −class Animal {    public void move() {       System.out.println("Animals can move");    } } class Dog extends Animal {    public void move() {       System.out.println("Dogs can walk and run"); ...

Read More
Showing 1141–1150 of 4,496 articles
« Prev 1 113 114 115 116 117 450 Next »
Advertisements