UEC2023155 Assignment 10
UEC2023155 Assignment 10
Title :
a) Program on simple inheritance
b) Program to demonstrate Member access and inheritance
c) Program to demonstrate mul level inheritance without and with the use of
thekeyword super
d) Program to demonstrate Method Overriding.
class A {
int i, j; void
showij() {
System.out.println (i+ " " +j);
}
}
a.i = 10;
a.j = 20;
b.i = 100;
b.j = 200;
b.k = 300;
a.showij();
b.showij();
b.sum();
}
}
(base) ccoew@etccomplab5:~/Desktop/UEC2023123$ javac ShowInherit.java
(base) ccoew@etccomplab5:~/Desktop/UEC2023123$ java ShowInherit
10 20 100
200 i+j+k =
600
double vol;
vol = mybox1.volume ();
System.out.println ("The volume of the mybox1 is " + vol);
System.out.println ("The weight of the mybox1 is " + mybox1.weight);
void displayDetails () {
System.out.println ("Name | " + name);
System.out.println ("Age | " + age);
System.out.println ("City | " + city);
System.out.println ("Played | " +gamesPlayed);
System.out.println ("Type | " + type);
}
}
class Cricket extends Player {
int runs; int wickets;
var1.getDetails();
var1.displayDetails ();
var2.getDetails();
var2.displayDetails ();
var3.getDetails ();
var3.displayDetails ();
}
}
(base) ccoew@etccomplab5:~/Desktop/UEC2023123$ javac Inherit.java
(base) ccoew@etccomplab5:~/Desktop/UEC2023123$ java Inherit
Enter the name of the player: Sachin
Enter the age of the player: 34
Enter the city: Pune
Enter the number of games played by the player: 100
Enter the type of the game: Cricket
Enter the runs made by the player: 100
Enter the wickets taken by the player: 50
Name | Sachin
Age | 34
City | Pune
Played | 100
Type | Cricket
Runs | 100
Wickets | 50
Enter the name of the player: Nehman
Enter the age of the player: 29
Enter the city: Mumbai
Enter the number of games played by the player: 40
Enter the type of the game: Football
Enter the goals made by the player: 100
Name | Nehman
Age | 29
City | Mumbai
Played | 40
Type | Football
Goals | 100
Enter the name of the player: Virat
Enter the age of the player: 35
Enter the city: Kolkata
Enter the number of games played by the player: 50
Enter the type of the game: Hockey
Enter the goals made by the player: 100
Name | Virat
Age | 35
City | Kolkata
Played | 50
Type | Hockey
Goals | 100
class Figure { double dim1,
dim2;
double area () {
System.out.println ("The Area is undefined :"); return
0;
}
}
figref;
figref = r;
System.out.print ("The Area of the Rectangle is "+ figref.area());
figref = t;
System.out.print ("The Area of the Triangle is "+figref.area());
}
}
(base) ccoew@etccomplab5:~/Desktop/UEC2023123$ javac AreaRectTri.java
(base) ccoew@etccomplab5:~/Desktop/UEC2023123$ java AreaRectTri
The Area of the Rectangle is 200.0The Area of the Triangle is 600.0(base)