• Write a java program to implement hybrid inheritance
// Interface 1
interface Student {
void getDetails(String name, int rollNo);
}
// Interface 2
interface Marks {
void getMarks(int m1, int m2, int m3);
}
// Base class
class Person {
String name;
int rollNo;
void displayDetails() {
[Link]("Name: " + name);
[Link]("Roll No: " + rollNo);
}
}
// Derived class using hybrid inheritance
class Result extends Person implements Student, Marks {
int m1, m2, m3, total;
double percentage;
public void getDetails(String name, int rollNo) {
[Link] = name;
[Link] = rollNo;
}
public void getMarks(int m1, int m2, int m3) {
this.m1 = m1;
this.m2 = m2;
this.m3 = m3;
calculateResult();
}
void calculateResult() {
total = m1 + m2 + m3;
percentage = total / 3.0;
}
void displayResult() {
displayDetails();
[Link]("Marks: " + m1 + ", " + m2 + ", " + m3);
[Link]("Total: " + total);
[Link]("Percentage: " + percentage + "%");
}
}
// Main class
public class HybridInheritanceExample {
public static void main(String[] args) {
Result student1 = new Result();
[Link]("Asha", 101);
[Link](85, 90, 88);
[Link]();
}
}
• Write a java program to find transpose of a Matrix
import [Link];
public class TransposeMatrix {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Input the size of the matrix
[Link]("Enter number of rows: ");
int rows = [Link]();
[Link]("Enter number of columns: ");
int cols = [Link]();
int[][] matrix = new int[rows][cols];
int[][] transpose = new int[cols][rows];
// Input matrix elements
[Link]("Enter matrix elements:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
matrix[i][j] = [Link]();
}
}
// Calculate transpose
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
transpose[j][i] = matrix[i][j];
}
}
// Display original matrix
[Link]("\nOriginal Matrix:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
[Link](matrix[i][j] + " ");
}
[Link]();
}
// Display transpose matrix
[Link]("\nTranspose of Matrix:");
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
[Link](transpose[i][j] + " ");
}
[Link]();
}
[Link]();
}
}