Date: Page No.
WEEK-1:
Objective: Introduction to Java Basics and Class Fundamentals
Experiment – 01
Aim: Write a simple JAVA program that prints "Hello, World!" to the console.
Code Snippet:
public class HelloWorld {
public static void main (String[] args) {
[Link]("Hello, World!");
}
}
Output:
Hello, World!
Experiment – 02
a. Aim: Write a JAVA program to perform addition of two numbers using command line
arguments.
Code Snippet:
public class Numbers {
public static void main(String[] args) {
if ([Link] != 2) {
[Link]("Please provide exactly two numbers as command line arguments.");
return;
}
int num1 = [Link](args[0]);
int num2 = [Link](args[1]);
int sum = num1 + num2;
[Link]("The sum of " + num1 + " and " + num2 + " is: " + sum);
}
}
Output:
10 13
The sum of 10 and 13 is 23
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
b. Aim: Write a JAVA program to perform addition of two numbers using Scanner Class.
Code Snippet:
import [Link];
public class Addition {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the first number: ");
int firstNumber = [Link]();
[Link]("Enter the second number: ");
int secondNumber = [Link]();
int sum = firstNumber + secondNumber;
[Link]("The sum of " + firstNumber + " and " + secondNumber + " is: " + sum);
[Link]();
}
}
Output:
Enter the first number: 90
Enter the second number: 35
Addition of 90 and 35 is 125
Experiment – 03
Aim: Write a JAVA program to display default value of all primitive data types of JAVA.
Code Snippet:
public class DefaultValues {
public static void main(String[] args) {
boolean boolValue = false; // Default value is false
char charValue = '\u0000'; // Default value is null character
byte byteValue = 0; // Default value is 0
short shortValue = 0; // Default value is 0
int intValue = 0; // Default value is 0
long longValue = 0L; // Default value is 0L
float floatValue = 0.0f; // Default value is 0.0f
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
double doubleValue = 0.0; // Default value is 0.0
[Link]("Default values of primitive data types in Java:");
[Link]("boolean: " + boolValue);
[Link]("char: " + charValue);
[Link]("byte: " + byteValue);
[Link]("short: " + shortValue);
[Link]("int: " + intValue);
[Link]("long: " + longValue);
[Link]("float: " + floatValue);
[Link]("double: " + doubleValue);
}
}
Output:
Default values of primitive data types in Java:
boolean: false
char:
byte: 0
short: 0
int: 0
long: 0
float: 0.0
double: 0.0
Experiment – 04
Aim: Write a JAVA program that displays the roots of a quadratic equation ax2+bx+c=0. Calculate
the discriminant D and basing on the value of D, describe the nature of roots.
Code Snippet:
import [Link];
public class QuadraticEquation {
public static void main(String[] args) {
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
Scanner scanner = new Scanner([Link]);
[Link]("Enter coefficients a, b, and c: ");
double a = [Link]();
double b = [Link]();
double c = [Link]();
double D = b * b - 4 * a * c; // Calculate the discriminant
if (D > 0) {
double root1 = (-b + [Link](D)) / (2 * a);
double root2 = (-b - [Link](D)) / (2 * a);
[Link]("Roots are real and different: " + root1 + " and " + root2);
} else if (D == 0) {
double root = -b / (2 * a);
[Link]("Roots are real and the same: " + root);
} else {
[Link]("Roots are complex and conjugate.");
}
[Link]();
}
}
Output:
Enter coefficients a, b, and c: 1 6 1
Roots are real and different: -0.1715728752538097 and -5.82842712474619
Experiment – 05
Aim: Write a JAVA program to illustrate increment/decrement and bitwise operators.
Code Snippet:
public class OperatorDemo {
public static void main(String[] args) {
int a = 5;
int b = 3;
[Link]("Initial value of a: " + a);
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
[Link]("Increment a: " + (++a));
[Link]("Decrement a: " + (--a));
[Link]("Bitwise AND (a & b): " + (a & b));
[Link]("Bitwise OR (a | b): " + (a | b));
[Link]("Bitwise XOR (a ^ b): " + (a ^ b));
[Link]("Bitwise NOT (~a): " + (~a));
}
}
Output:
Initial value of a: 5
Increment a: 6
Decrement a: 5
Bitwise AND (a & b): 1
Bitwise OR (a | b): 7
Bitwise XOR (a ^ b): 6
Bitwise NOT (~a): -6
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
WEEK-2:
Objective: Control and iteration statements, Classes and Methods
Experiment – 01
Aim: Write a program to create illustration of a class and definition of an object in java.
Code Snippet:
class Car {
private String make;
private String model;
private int year;
public Car(String make, String model, int year) {
[Link] = make;
[Link] = model;
[Link] = year;
}
public void displayDetails() {
[Link]("Car Make: " + make);
[Link]("Car Model: " + model);
[Link]("Car Year: " + year);
}
}
public class Main {
public static void main(String[] args) {
Car myCar = new Car("Toyota", "Corolla", 2020);
[Link]();
}
}
Output:
Car Make: Toyota
Car Model: Corolla
Car Year: 2020
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
Experiment – 02
Aim: Write a java program to illustrate selection statement.
Code Snippet:
import [Link];
public class SSE {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter your score: ");
int score = [Link]();
if (score >= 90) {
[Link]("Grade: A");
} else if (score >= 80) {
[Link]("Grade: B");
} else if (score >= 70) {
[Link]("Grade: C");
} else if (score >= 60) {
[Link]("Grade: D");
} else {
[Link]("Grade: F");
}
[Link]();
}
}
Output:
Enter your score: 91
Grade: A
Experiment – 03
Aim: Write a java program to illustrate looping statement.
Code Snippet:
public class LoopingExample {
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
public static void main(String[] args) {
[Link]("Using for loop: ");
for (int i = 1; i <= 5; i++) {
[Link](i + " ");
}
[Link]("\nUsing while loop: ");
int j = 1;
while (j <= 5) {
[Link](j + " ");
j++;
}
[Link]("\nUsing do-while loop: ");
int k = 1;
do {
[Link](k + " ");
k++;
} while (k <= 5);
}
}
Output:
Using for loop: 1 2 3 4 5
Using while loop: 1 2 3 4 5
Using do-while loop: 1 2 3 4 5
Experiment – 04
Aim: Write a java program to display fibonacci sequence.
Code Snippet:
import [Link];
public class FibonacciSequence {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
[Link]("Enter the number of terms in the Fibonacci sequence: ");
int terms = [Link]();
int firstTerm = 0, secondTerm = 1;
[Link]("\nFibonacci Sequence up to " + terms + " terms: ");
for (int i = 1; i <= terms; i++) {
[Link](firstTerm + " ");
int nextTerm = firstTerm + secondTerm;
firstTerm = secondTerm;
secondTerm = nextTerm;
}
[Link]();
}
}
Output:
Enter the number of terms in the Fibonacci sequence: 5
Fibonacci Sequence up to 5 terms: 0 1 1 2 3
Experiment – 05
Aim: Write a java program to illustrate method overloading.
Code Snippet:
public class MethodOverloadingExample {
public int add(int a, int b) {
return a + b;
}
public int add(int a, int b, int c) {
return a + b + c;
}
public double add(double a, double b) {
return a + b;
}
public static void main(String[] args) {
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
MethodOverloadingExample example = new MethodOverloadingExample();
[Link]("Sum of 5 and 10: " + [Link](5, 10)+"\nSum of 5, 10, and 15: " +
[Link](5, 10, 15)+"\nSum of 5.5 and 10.5: " + [Link](5.5, 10.5));
}
}
Output:
Sum of 5 and 10: 15
Sum of 5, 10, and 15: 30
Sum of 5.5 and 10.5: 16.0
Experiment – 06
Aim: Write a java program to illustrate parameter passing technique.
Code Snippet:
public class ParameterPassing {
public static void callByValue(int number) {
number = number + 10; // Modifying the local copy
[Link]("Inside callByValue method: " + number);
}
public static void callByReference(MyObject obj) {
[Link] = [Link] + 10; // Modifying the object's property
[Link]("Inside callByReference method: " + [Link]);
}
public static void main(String[] args) {
int num = 5;
[Link]("Before callByValue method: " + num);
callByValue(num);
[Link]("After callByValue method: " + num);
MyObject myObj = new MyObject(5);
[Link]("Before callByReference method: " + [Link]);
callByReference(myObj);
[Link]("After callByReference method: " + [Link]);
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
}
}
class MyObject {
int value;
MyObject(int value) {
[Link] = value;
}
}
Output:
Before callByValue method: 5
Inside callByValue method: 15
After callByValue method: 5
Before callByReference method: 5
Inside callByReference method: 15
After callByReference method: 15
Experiment – 07
Aim: Write a java program to illustrate default and parameterized constructor.
Code Snippet:
class Student {
private String name;
public Student() {
[Link] = "Unknown";
[Link] = 0;
}
public Student (String name, int age) {
[Link] = name;
[Link] = age;
}
public void displayDetails() {
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
[Link]("Name: " + name);
[Link]("Age: " + age);
}
}
public class Main {
public static void main (String[] args) {
Student student1 = new Student();
[Link]();
Student student2 = new Student("Alice", 20);
[Link]();
}
}
Output:
Name: Unknown
Age: 0
Name: Alice
Age: 20
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
WEEK-3:
Objective: Arrays and Strings.
Experiment – 01
Aim: Write a JAVA program to read and display array of integers using 1D and 2D.
Code Snippet:
import [Link];
public class ArrayDisplay {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the number of elements in the 1D array: ");
int size1D = [Link]();
int[] oneDArray = new int[size1D];
[Link]("Enter " + size1D + " integers for the 1D array:");
for (int i = 0; i < size1D; i++) {
oneDArray[i] = [Link]();
}
[Link]("1D Array Elements:");
for (int num : oneDArray) {
[Link](num + " ");
}
[Link]();
[Link]("Enter the number of rows in the 2D array: ");
int rows = [Link]();
[Link]("Enter the number of columns in the 2D array: ");
int cols = [Link]();
int[][] twoDArray = new int[rows][cols];
[Link]("Enter " + (rows * cols) + " integers for the 2D array:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
twoDArray[i][j] = [Link]();
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
}
}
[Link]("2D Array Elements:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
[Link](twoDArray[i][j] + " ");
}
[Link]();
}
[Link]();
}
}
Output:
Enter the number of elements in the 1D array: 6
Enter 6 integers for the 1D array:
123456
1D Array Elements:
123456
Enter the number of rows in the 2D array: 3
Enter the number of columns in the 2D array: 2
Enter 6 integers for the 2D array:
123456
2D Array Elements:
123
456
Experiment – 02
Aim: Write a JAVA program to sort given list of numbers.
Code Snippet:
import [Link].*;
public class NumberSorter {
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
public static void main(String[] args) {
List<Integer> numbers = new ArrayList<>();
[Link](34);
[Link](12);
[Link](5);
[Link](78);
[Link](23);
[Link]("Original list: " + numbers);
[Link](numbers);
[Link]("Sorted list: " + numbers);
}
}
Output:
Original list: [34, 12, 5, 78, 23]
Sorted list: [5, 12, 23, 34, 78]
Experiment – 03
Aim: Write a JAVA program to search for an element using linear search.
Code Snippet:
import [Link];
public class LinearSearch {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
int[] array = {5, 3, 8, 4, 2};
[Link]("Enter the element to search: ");
int target = [Link]();
int index = linearSearch(array, target);
if (index != -1) {
[Link]("Element found at index: " + index);
} else {
[Link]("Element not found in the array.");
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
}
[Link]();
}
public static int linearSearch(int[] array, int target) {
for (int i = 0; i < [Link]; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
}
Output:
Enter the element to search: 8
Element found at index: 2
Experiment – 04
a. Aim: Write a JAVA program to determine the addition of two matrices.
Code Snippet:
import [Link];
public class MatrixAddition {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the number of rows: ");
int rows = [Link]();
[Link]("Enter the number of columns: ");
int cols = [Link]();
int[][] matrixA = new int[rows][cols];
int[][] matrixB = new int[rows][cols];
int[][] resultMatrix = new int[rows][cols];
[Link]("Enter elements of the first matrix:");
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
[Link]("Element [" + i + "][" + j + "]: ");
matrixA[i][j] = [Link]();
}
}
[Link]("Enter elements of the second matrix:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
[Link]("Element [" + i + "][" + j + "]: ");
matrixB[i][j] = [Link]();
}
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
resultMatrix[i][j] = matrixA[i][j] + matrixB[i][j];
}
}
[Link]("Resultant Matrix after Addition:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
[Link](resultMatrix[i][j] + " ");
}
[Link]();
}
[Link]();
}
}
Output:
Enter the number of rows: 3
Enter the number of columns: 2
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
Enter elements of the first matrix:
Element [0][0]: 1
Element [0][1]: 2
Element [1][0]: 3
Element [1][1]: 1
Element [2][0]: 2
Element [2][1]: 3
Enter elements of the second matrix:
Element [0][0]: 3
Element [0][1]: 2
Element [1][0]: 1
Element [1][1]: 3
Element [2][0]: 2
Element [2][1]: 1
Resultant Matrix after Addition:
44
44
44
b. Aim: Write a JAVA program to determine the multiplication of two matrices.
Code Snippet:
import [Link];
public class MatrixMultiplication {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the number of rows for the first matrix: ");
int rows1 = [Link]();
[Link]("Enter the number of columns for the first matrix: ");
int cols1 = [Link]();
[Link]("Enter the number of rows for the second matrix: ");
int rows2 = [Link]();
[Link]("Enter the number of columns for the second matrix: ");
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
int cols2 = [Link]();
if (cols1 != rows2) {
[Link]("Matrix multiplication is not possible. The number of columns in the first
matrix must equal the number of rows in the second matrix.");
return;
}
int[][] matrix1 = new int[rows1][cols1];
int[][] matrix2 = new int[rows2][cols2];
int[][] product = new int[rows1][cols2];
[Link]("Enter elements of the first matrix:");
for (int i = 0; i < rows1; i++) {
for (int j = 0; j < cols1; j++) {
matrix1[i][j] = [Link]();
}
}
[Link]("Enter elements of the second matrix:");
for (int i = 0; i < rows2; i++) {
for (int j = 0; j < cols2; j++) {
matrix2[i][j] = [Link]();
}
}
for (int i = 0; i < rows1; i++) {
for (int j = 0; j < cols2; j++) {
for (int k = 0; k < cols1; k++) {
product[i][j] += matrix1[i][k] * matrix2[k][j];
}
}
}
[Link]("Product of the two matrices:");
for (int i = 0; i < rows1; i++) {
for (int j = 0; j < cols2; j++) {
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
[Link](product[i][j] + " ");
}
[Link]();
}
[Link]();
}
}
Output:
Enter the number of rows for the first matrix: 2
Enter the number of columns for the first matrix: 3
Enter the number of rows for the second matrix: 3
Enter the number of columns for the second matrix: 2
Enter elements of the first matrix:
123123
Enter elements of the second matrix:
123123
Product of the two matrices:
13 13
13 13
Experiment – 05
Aim: Write a JAVA program to illustrate passing Arrays as parameters to methods.
Code Snippet:
public class ArrayParameterExample {
public static void printArray(int[] array) {
[Link]("Array Elements:");
for (int element : array) {
[Link](element + " ");
}
[Link]();
}
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
public static int sumArray(int[] array) {
int sum = 0;
for (int element : array) {
sum += element;
}
return sum;
}
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
printArray(numbers);
int totalSum = sumArray(numbers);
[Link]("Sum of Array Elements: " + totalSum);
}
}
Output:
Array Elements:
12345
Sum of Array Elements: 15
Experiment – 06
Aim: Write a JAVA program to check string palindrome property
Code Snippet:
import [Link];
public class PalindromeChecker {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a string: ");
String input = [Link]();
if (isPalindrome(input)) {
[Link]("The string is a palindrome.");
} else {
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
[Link]("The string is not a palindrome.");
}
[Link]();
}
public static boolean isPalindrome(String str) {
String cleanedStr = [Link]("[\\W]", "").toLowerCase();
int left = 0;
int right = [Link]() - 1;
while (left < right) {
if ([Link](left) != [Link](right)) {
return false;
}
left++;
right--;
}
return true;
}
}
Output:
Enter a string: JAVA
The string is not a palindrome.
Experiment – 07
Aim: Write a JAVA program to illustrate String handling methods (charAt, compareTo, equals.
indexOf), joinO, replace, substring(). toUpperCase(), toLowerCase()).
Code Snippet:
public class StringHandlingExample {
public static void main(String[] args) {
String str1 = "Hello, World!";
String str2 = "Hello, Java!";
char characterAtIndex = [Link](7);
[Link]("Character at index 7: " + characterAtIndex);
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
int comparisonResult = [Link](str2);
[Link]("Comparison result: " + comparisonResult);
boolean areEqual = [Link](str2);
[Link]("Are str1 and str2 equal? " + areEqual);
int indexOfWorld = [Link]("World");
[Link]("Index of 'World': " + indexOfWorld);
String joinedString = [Link](" ", "Hello", "from", "Java");
[Link]("Joined String: " + joinedString);
String replacedString = [Link]("World", "Java");
[Link]("Replaced String: " + replacedString);
String substring = [Link](7, 12);
[Link]("Substring (index 7 to 12): " + substring);
String upperCaseString = [Link]();
[Link]("Uppercase String: " + upperCaseString);
String lowerCaseString = [Link]();
[Link]("Lowercase String: " + lowerCaseString);
}
}
Output:
Character at index 7: W
Comparison result: 13
Are str1 and str2 equal? false
Index of 'World': 7
Joined String: Hello from Java
Replaced String: Hello, Java!
Substring (index 7 to 12): World
Uppercase String: HELLO, WORLD!
Lowercase String: hello, world!
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
WEEK-4:
Objective: Static members, String buffer and Inheritance.
Experiment – 01
Aim: Write a JAVA program to illustrate Static Variable, Static Method, and Static Block.
Code Snippet:
public class StaticExample {
static int staticVariable = 10;
static {
[Link]("Static block executed. Static variable initialized to: " + staticVariable);
}
static void staticMethod() {
[Link]("Static method called. Static variable value: " + staticVariable);
}
public static void main(String[] args) {
[Link]("Accessing static variable directly: " + staticVariable);
staticMethod();
}
}
Output:
Static block executed. Static variable initialized to: 10
Accessing static variable directly: 10
Static method called. Static variable value: 10
Experiment – 02
Aim: Write a JAVA program to sort an array of strings.
Code Snippet:
import [Link];
public class StringArraySorter {
public static void main(String[] args) {
String[] stringArray = {"Banana", "Apple", "Orange", "Mango", "Grapes"};
[Link]("Original Array: " + [Link](stringArray));
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
[Link](stringArray);
[Link]("Sorted Array: " + [Link](stringArray));
}
}
Output:
Original Array: [Banana, Apple, Orange, Mango, Grapes]
Sorted Array: [Apple, Banana, Grapes, Mango, Orange]
Experiment – 03
Aim: Write a JAVA program to illustrate five String Buffer handling methods.
Code Snippet:
public class StringBufferExample {
public static void main(String[] args) {
StringBuffer stringBuffer = new StringBuffer("Hello");
[Link](" World!");
[Link]("After append: " + stringBuffer);
[Link](5, ",");
[Link]("After insert: " + stringBuffer);
[Link](5, 6);
[Link]("After delete: " + stringBuffer);
[Link]();
[Link]("After reverse: " + stringBuffer);
[Link]("Current capacity: " + [Link]());
}
}
Output:
After append: Hello World!
After insert: Hello, World!
After delete: Hello World!
After reverse: !dlroW olleH
Current capacity: 21
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
Experiment – 04
Aim: Write a JAVA program to illustrate Inheritance, Member access, Types of Inheritance, Forms
of inheritance.
Code Snippet:
class LibraryItem {
private String title;
private String author;
public LibraryItem(String title, String author) {
[Link] = title;
[Link] = author;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public void displayInfo() {
[Link]("Title: " + title + ", Author: " + author);
}
}
class Book extends LibraryItem {
private String isbn;
public Book(String title, String author, String isbn) {
super(title, author);
[Link] = isbn;
}
public String getIsbn() {
return isbn;
}
public void displayInfo() {
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
[Link]();
[Link]("ISBN: " + isbn);
}
}
class Magazine extends LibraryItem {
private int issueNumber;
public Magazine(String title, String author, int issueNumber) {
super(title, author);
[Link] = issueNumber;
}
public int getIssueNumber() {
return issueNumber;
}
public void displayInfo() {
[Link]();
[Link]("Issue Number: " + issueNumber);
}
}
public class LibraryManagement {
public static void main(String[] args) {
LibraryItem book = new Book("Effective Java", "Joshua Bloch", "978-0134686097");
LibraryItem magazine = new Magazine("National Geographic", "Various", 202);
[Link]();
[Link]();
}
}
Output:
Title: Effective Java, Author: Joshua Bloch
ISBN: 978-0134686097
Title: National Geographic, Author: Various
Issue Number: 202
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
Experiment – 05
Aim: Write a JAVA program to illustrate the uses of Super key word.
Code Snippet:
class Animal {
String sound;
Animal(String sound) {
[Link] = sound;
}
void makeSound() {
[Link]("Animal makes sound: " + sound);
}
}
class Dog extends Animal {
String breed;
Dog(String sound, String breed) {
super(sound);
[Link] = breed;
}
void displayInfo() {
makeSound();
[Link]("Dog breed: " + breed);
}
}
public class SuperKeywordExample {
public static void main(String[] args) {
Dog dog = new Dog("Bark", " Shih Tzu ");
[Link]();
}
}
Output:
Animal makes sound: Bark
Advanced Java Programming Lab Reg No: 23331A4756
Date: Page No.
Dog breed: Shih Tzu
Experiment – 06
Aim: Write a JAVA program to illustrate Methods overriding.
Code Snippet:
class Animal {
void sound() {
[Link]("Animal makes a sound");
}
}
class Dog extends Animal {
void sound() {
[Link]("Dog barks");
}
}
class Cat extends Animal {
void sound() {
[Link]("Cat meows");
}
}
public class MethodOverridingExample {
public static void main(String[] args) {
Animal myDog = new Dog();
Animal myCat = new Cat();
[Link]();
[Link]();
}
}
Output:
Dog barks
Cat meows
Advanced Java Programming Lab Reg No: 23331A4756