Professional Documents
Culture Documents
WT File 2nd Part
WT File 2nd Part
public static int[][] multiplyMatrices(int[][] firstMatrix, int[][] secondMatrix, int rowsFirst, int
columnsFirst, int columnsSecond) {
int[][] product = new int[rowsFirst][columnsSecond];
return product;
}
}
Output:
Experiment 6
Aim:
Write a program in java to demonstrate the new keyword and dot operator using addition and subtraction
method.
Introduction: The new keyword in Java is used to create an instance of a class, also known as an object.
It is used to allocate memory for the object on the heap, the memory space where objects are stored. It
calls the constructor of a class to initialize the object's state.
The dot operator (“.”) is used frequently to access a field or to call a method on an object.
Output:
Experiment 7
Aim:
Write a program in java to demonstrate the default constructor and parameterized constructor.
Introduction: In Java, a constructor is a block of codes similar to the method. It is called when an
instance of the class is created. It is a special type of method which is used to initialize the object.
Default constructor is one which doesn’t consist of any parameters and is created automatically in case
no constructors are defined by the programmer.
Parameterized constructors are used to create objects with differing values or of same values too. They
are differentiated by the compiler by the number of parameters in the list and their types.
Output:
Experiment 8
Aim:
Write a program in java to demonstrate the constructor overloading.
Introduction: Constructor overloading in Java involves creating multiple constructors in a class with
different parameter lists so that every constructor can perform a different task. They are differentiated by
the compiler by the number of parameters in the list and their types.
Output:
Experiment 9
Aim:
Write a program in java to demonstrate the method overloading using addition method.
Introduction: Method overloading in Java involves creating multiple methods with the same name but
with different parameter lists and different types.
Source Code:
public class Example{
Output:
Experiment 10
Aim:
Write a program in java to demonstrate the static keyword.
Introduction: The static keyword is used to create variables and methods that belong to the class itself
rather than to instances of the class. The static keyword is used for memory management mainly. Static
variables have the property of preserving their value even after they are out of their scope. Static methods
can be called directly without having to create an instance of the class.
Counter(){ count++;
}
Output: