-
Random Number Generation with Java
Using the Random Class generate a random number is to use the Java Random class of the java.util package. It generates a stream of pseudorandom numbers. We can generate a random number of any data type, such as integer, float, double, Boolean, long. If you are going to use this class to generate random numbers,…
-
Interface
An interface is a fully abstract class. It includes a group of abstract methods (methods without a body). We use the interface keyword to create an interface in Java. For example, interface Language { public void getType(); public void getVersion(); } Notes on Interfaces: Why And When To Use Interfaces? 1) To achieve security –…
-
Abstract Classes and Methods
Why And When To Use Abstract Classes and Methods? To achieve security – hide certain details and only show the important details of an object. Abstract Classes and Methods Data abstraction is the process of hiding certain details and showing only essential information to the user. Remember from the Inheritance chapter that we use the…
-
pass objects as an argument in Java
Object as an Argument in Java Object as an argument is use to establish communication between two or more objects of same class as well as different class, i.e, user can easily process data of two same or different objects within function. In Java, When a primitive type is passed to a method ,it is…
-
Inheritance in Java
Single Inheritance When a class inherits another class, it is known as a single inheritance. In the example given below, Dog class inherits the Animal class, so there is the single inheritance. Multilevel Inheritance When there is a chain of inheritance, it is known as multilevel inheritance. As you can see in the example given…
-
Inheritance
what is inheritance? 1.The new class that is created is known as subclass (child or derived class) and the existing class from where the child class is derived is known as superclass (parent or base class). 2.Inheritance in Java is a process of acquiring all the behaviours of a parent object. 1. Single Inheritance In…