0% found this document useful (0 votes)
1 views4 pages

Java_Lab_Record_953325104044

The document contains two Java program exercises demonstrating object-oriented programming concepts. The first exercise focuses on constructors and static members, showcasing parameterized constructors and static methods to manage shared data. The second exercise illustrates inheritance, implementing single and hierarchical inheritance with method overriding to demonstrate code reusability.

Uploaded by

selvame804
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

Java_Lab_Record_953325104044

The document contains two Java program exercises demonstrating object-oriented programming concepts. The first exercise focuses on constructors and static members, showcasing parameterized constructors and static methods to manage shared data. The second exercise illustrates inheritance, implementing single and hierarchical inheritance with method overriding to demonstrate code reusability.

Uploaded by

selvame804
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Reg No: 953325104044

[Link]: 1 Constructor and Static Members

Date:

Aim:
To write a Java program demonstrating the use of parameterized constructors, constructor overloading,
and static members (variables and methods) to manage shared data across objects.

Algorithm:
Step 1: Define a class Student with instance variables (rollNo, name) and a static variable (collegeName).
Step 2: Implement a parameterized constructor to initialize instance variables.
Step 3: Implement a static method changeCollege() to update the static variable collegeName.
Step 4: Define a display method to print student details along with collegeName.
Step 5: In the main method, instantiate Student objects, invoke instance methods, and call the static
method using the class name.

Program:
class Student{
String name;
Student(String s,int a){
name=s;
}
static String college = " Unnamalai Institute of Technology ";
void display ()
{
[Link]("Name :"+ name + " CollegeName:"+college);
}
static void Changecollege( String Newcollege){
college=Newcollege;
}
}
class Static{
public static void main(String args[]){
Student s1=new Student("santo");
Student s2=new Student("anto");
[Link]("--------Initial Student Details-----");
[Link]();
[Link]();
[Link]("Anna University");
[Link]("--------Updated Student Details-----");
[Link]();
[Link]();
}
}

Output:
uit@uit-HP-Elite-7100-Microtower-PC:~$ cd santhosh
uit@uit-HP-Elite-7100-Microtower-PC:~/santhosh$ javac [Link]
uit@uit-HP-Elite-7100-Microtower-PC:~/santhosh$ java Student
----Student deteils----
Rollno:101,Name:santo,college:Unnamalai Institute of Technology
Rollno:102,Name:anto,college:Unnamalai Institute of Technology
----updated Student details----
Rollno:101,Name:santo,college:Anna University
Rollno:102,Name:anto,college:Anna University
uit@uit-HP-Elite-7100-Microtower-PC:~/santhosh$

Result:
Thus, the java program Constructor and Static Members was executed Successfully.
Reg No: 953325104044

[Link]: 2 Inheritance

Date:

Aim:
To implement single and hierarchical inheritance in Java using base and derived classes, demonstrating
code reusability and method overriding.

Algorithm:
Step 1: Create a superclass Employee with fields id and name, and a method displayEmpDetails().
Step 2: Create a subclass Developer that extends Employee and adds a field programmingLanguage.
Step 3: Override the displayEmpDetails() method using super to call superclass properties.
Step 4: In the main method, instantiate Developer, assign values, and execute methods to verify
inheritance.

Program:
class Empdetails{
String name;
int empid;
double salary;
Empdetails(String n,int r,double s){
[Link]=n;
[Link]=r;
[Link]=s;
}
void display(){
[Link]("Employee Name:"+name);
[Link]("Employee id:"+empid);
[Link]("Employee Salary:"+salary);
}
}
class Empskills extends Empdetails{
String skills;
Empskills(String n,int r,double s,String skills)
{
super(n,r,s);
[Link]=skills;
}
void display(){
[Link]();
[Link]("Employee Skills:"+skills);
}
public static void main(String []args)
{
Empskills e1=new Empskills("Santhosh",240,75000,"FullStack Developer");
[Link]("--- Employee Profile ---");
[Link]();
}
}

Output:

C:\Users\santhosh\OneDrive\Desktop\javatest>javac [Link]

C:\Users\santhosh\OneDrive\Desktop\javatest>java Empskills
--- Employee Profile ---
Employee Name:Santhosh
Employee id:240
Employee Salary:75000.0
Employee Skills:FullStack Developer

C:\Users\santhosh\OneDrive\Desktop\javatest>

Result:
Thus, the java program Inheritance was executed Successfully.

You might also like