GithubHelp home page GithubHelp logo

data-of-members-in-class's Introduction

Data-of-Members-in-Class

AIM:

To Write a Java program to create a class.

Create a class named 'Member' having the following members:
Data members:
1 - Name
2 - Age
3 - Phone number
4 - Address
5 - Salary

It also has a method named 'printSalary' which prints the salary of the members. Two classes 'Employee' and 'Manager' inherits the 'Member' class. The 'Employee' and 'Manager' classes have data members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a manager by making an object of both of these classes and print the same.

ALGORITHM:

Step 1:

Create a class named 'Member'.

Step 2:

Add the following data members to the 'Member' class: Name (String), Age (int), Phone number (String), Address (String), Salary (double).

Step 3:

Add a method named 'printSalary' to the 'Member' class, Inside the method, print the value of the 'Salary' data member.

Step 4:

Create a class named 'Employee' that inherits from the 'Member' class.

Step 5:

Create a class named 'Manager' that also inherits from the 'Member' class.

Step 6:

In the 'Main' class, create an object of the 'Employee' class and name it 'employee'. Assign values to the data members of 'employee'. Create an object of the 'Manager' class and name it 'manager'.Assign values to the data members of 'manager'.

Step 7:

Call the 'printSalary' method for both 'employee' and 'manager' objects to print their salaries.

PROGRAM:

Member.java:

public class Member
{
    public void Name(String name)
    {
        System.out.println(name);
    }
    public void Age(int age)
    {
        System.out.println(age);
    }
    public void PhoneNumber(String num)
    {
        System.out.println(num);
    }
    public void Address(String adrs)
    {
        System.out.println(adrs);
    }
    public void printSalary(int salary)
    {
        System.out.println(salary);
    }
}

Employee.java:

public class Employee extends Member
{
    public void specialization(String specialization)
    {
        System.out.println(specialization);
    }
}

Manager.java:

public class Manager extends Member
{
    public void Department(String dept)
    {
        System.out.println(dept);
    }
}

Details.java:

public class Details
{
    public static void main(String[] args)
    {
        System.out.println("Employee Details: ");
        Employee emp = new Employee();
        emp.Name("Kaz");
        emp.Age(21);
        emp.PhoneNumber("9873321560");
        emp.Address("Pune");
        emp.printSalary(27000);
        emp.specialization("Software Designer");
        System.out.print("\n");
        System.out.println("Manager Details: ");
        Manager man = new Manager();
        man.Name("Inej");
        man.Age(23);
        man.PhoneNumber("7852291046");
        man.Address("Mumbai");
        man.printSalary(50000);
        man.Department("AI Developer");

    }
}

OUTPUT:

image

RESULT:

Thus, the output is verified.

data-of-members-in-class's People

Contributors

harshavardhini33 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.