Author: Eric K

How to override Java Methods 0

How to override Java Methods

Overriding java methods happen in a case where a child class implements a method that is contained in super class.The main use of overriding is to provide a new implementation of a method. Overriding...

How to overload java methods by changing data type 0

How to overload java methods by changing data type

Below code shows how to overload java method by changing data type.See also Overloading java methods by changing the number of arguments.   public class MethodOverload { public void sumNumbers(int num1,int num2) { int...

How to overload java methods by changing number of arguments 0

How to overload java methods by changing number of arguments

The main reason why programmers overload methods are for easier readability.Think of a scenario where you have a method to multiply two numbers and another method multiply three numbers.These methods will have different names.Instead...

What is Aggregation in Java 0

What is Aggregation in Java

Aggregation in Java is very important because it makes code reusable.Think of a scenario where you’re creating a school-based management system.Student name, id, age are mandatory to be a caption in the system.Think of...

Multilevel Inheritance in  Java Example 0

Multilevel Inheritance in Java Example

In my previous post about Single level inheritance  I exampled how a child class can inherit methods from the parent class.Below code demonstrates, a more complex inheritance called Multilevel. public class Animal { void eat() {...

Simple Inheritance in Java 0

Simple Inheritance in Java

Below code shows a simple inheritance in java where class Dog inherits all class methods of parent class Animal. Animal Main Class public class Animal { void eat() { System.out.println(“All Animals eat”); } }...

Java program that takes two numbers as input  from a user and displays the product of two numbers. 0

Java program that takes two numbers as input from a user and displays the product of two numbers.

Below Java program code takes two integers from the user , multiplies  them and display import java.util.Scanner; public class JavaMultiply { public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print(“Input first...

Java program to divide two numbers and print on the screen 0

Java program to divide two numbers and print on the screen

Below java program code divided two numbers and prints the output on the screen. /** * * @author Eric * site www.techoverload.net */ public class JavaDivide { public static void main(String args[]) { int...

Write a Java program to print the sum of two numbers 0

Write a Java program to print the sum of two numbers

Below java program code prints sum of two numbers and displays the result. /** * * @author Eric * site www.techoverload.net */ public class JavaSum { public static void main(String args[]) { int num1=20;...

Write a Java program to display “Hello world” 0

Write a Java program to display “Hello world”

Below java program code is used to display “Hello World”  and print your name in a seperate line. /** * * @author Eric * Site:www.techoverload.net */ public class JavaHelloWord { public static void main(String...