0% found this document useful (0 votes)
2 views11 pages

Practical 8 Java

The document outlines a Java programming lab report by Juhi Anilkumar Kursija, focusing on inheritance and polymorphism concepts for code reusability. It includes examples of single, multilevel, and hierarchical inheritance, as well as polymorphism through various class implementations. The report demonstrates the practical application of these concepts with code snippets and expected outputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

Practical 8 Java

The document outlines a Java programming lab report by Juhi Anilkumar Kursija, focusing on inheritance and polymorphism concepts for code reusability. It includes examples of single, multilevel, and hierarchical inheritance, as well as polymorphism through various class implementations. The report demonstrates the practical application of these concepts with code snippets and expected outputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Shri Vile Parle Kelavani Mandal's

INSTITUTE OF TECHNOLOGY
DHULE (M.S.)
DEPARMENT OF COMPUTER ENGINEERING
Remark
Subject :JAVA Programming LAB

Name : Juhi Anilkumar Kursija Roll No. : 67

Class :[Link] Batch : S3 Division: B


Signature
Expt. No. :08 Date : 30-10-2025
Title : To study and implement the concepts of Inheritance and
Polymorphism in Java for achieving code reusability and dynamic method
execution.

Code:
//[Link] inheritance

import [Link].*;

class People
{
String name;
int age;

void getdata (String n, int a)


{
name = n;
age = a;
}
void display ()
{
[Link]("Name: " + name);
[Link]("Age: " + age);
}
}

class Student extends People


{
String course;
void get (String n, int a, String c)
{
getdata (n, a);
course = c;
}

void displayStudent ()
{
display ();
[Link]("Course: " + course);
}
}

public class SingleInheritance


{
public static void main (String[] args)
{
Student s = new Student();
s. get ("juhi kursija", 19, "Computer Engineering");
s. displayStudent();
}

Output:

Code:
//multiple inheritance

class Employee
{
String name;
int id;

void setEmployee (String n, int i)


{
name = n;
id = i;
}

void displayEmployee()
{
[Link]("Employee Name: " + name);
[Link]("Employee ID: " + id);
}
}

class Developer extends Employee


{
String pLanguage;

void setDeveloper (String n, int i, String lang)


{
setEmployee (n, i);
pLanguage = lang;
}

void displayDeveloper ()
{
displayEmployee();
[Link]("Programming Language:"+pLanguage);
}
}

class SeniorDeveloper extends Developer


{
int experience;
void setSeniorDeveloper(String n, int i, String lang, int exp)
{
setDeveloper(n, i, lang);
experience = exp;
}

void displaySeniorDeveloper()
{
displayDeveloper();
[Link]("Experience: " + experience + " years");
}
}

public class MultilevelInheritance


{
public static void main(String[] args)
{
SeniorDeveloper sd = new SeniorDeveloper();

[Link]("juhi ", 67, "Java", 5);


[Link]();
}
}
Output:
Code:
3. Hierarchical Inheritance

class Employee
{
String name;
int id;

void setEmployee(String n, int i)


{
name = n;
id = i;
}

void displayEmployee()
{
[Link]("Employee Name: " + name);
[Link]("Employee ID: " + id);
}
}

class Manager extends Employee


{
String department;

void setManager(String n, int i, String dept)


{
setEmployee(n, i);
department = dept;
}

void displayManager()
{
displayEmployee();
[Link]("Department: " + department);
}
}
class Developer extends Employee
{
String pLanguage;

void setDeveloper (String n, int i, String lang)


{
setEmployee(n, i);
pLanguage = lang;
}

void displayDeveloper()
{
displayEmployee();
[Link]("ProgrammingLanguage:"+pLanguage);
}
}
public class HierarchicalInheritance
{
public static void main(String[] args)
{

Manager m = new Manager();


[Link]("juhi kursija", 101, "Sales");
[Link]();

[Link]();

Developer d = new Developer();


[Link]("Prerna kursija", 102, "Java");
[Link]();
}
}
Output:

Code:
[Link]
class Shape
{
void draw()
{
[Link]("Drawing a shape");
}
}
class Circle extends Shape
{
void draw ()
{
[Link]("Drawing a circle");
}
}
class Rectangle extends Shape
{
void draw()
{
[Link]("Drawing a rectangle");
}
}
public class ShapeDemo
{
public static void main(String[] args)
{
Shape s;
s = new Circle();
[Link]();
s = new Rectangle();
[Link](); }
}
Output:

You might also like