Give an object that could be represented through super and sub classes? Give an example and describe what you think would be data member in the super class and then what would be data member in the subclass. Please create a UML diagram for one of the classes described. You can do this by inserting a table or list in the post or create it in Cacoo.
Here I have provided the answer for above question:
import java.lang.*;
import java.util.*;
//Parent (or) Super class
class Person
{
String name,address;
long phone_number;
String email_address;
public Person(String name,String address,long
phone_number,String email_address)
{
this.name=name;
this.address=address;
this.phone_number=phone_number;
this.email_address=email_address;
}
@Override
public String toString()
{
System.out.println("This is Person
class");
return
("Name:"+name+"\n"+"Address:"+address+"\n"+"PhoneNo:"+phone_number+"\n"+"Email:"+email_address+"\n");
}
}
//Child (or) Sub class
class Employee extends Person
{
String office;
double salary;
String date_hired;
public Employee(String name,String address,long
phone_number,String email_address,String office,double
salary,String date_hired)
{
super(name,address,phone_number,email_address); //this
will call the super class constructor.
this.office=office;
this.salary=salary;
this.date_hired=date_hired;
}
@Override
public String toString()
{
System.out.println("This is
Employee class");
return
(super.toString()+"Office:"+office+"\n"+"salary:"+salary+"\n"+"Date
Hired:"+date_hired+"\n");
// here super.toString()
calls the method in super class,super key word is used to call
super class membes
}
}
//Child (or) Sub class
class Student extends Person
{
String status;
public Student(String name,String address,long
phone_number,String email_address,String status)
{
super(name,address,phone_number,email_address); //this
will call the super class constructor.
this.status=status;
}
@Override
public String toString()
{
System.out.println("This is Student
class");
return (super.toString()+"Status of
student:"+status+"\n");
// here super.toString()
calls the method in super class,super key word is used to call
super class membes
}
}
//For Testing-----this class is used create object of sub
classes and
public class Test
{
public static void main(String args[])
{
Employee e=new
Employee("sofia","Kirlampudi",234234,"mail
address","ADP",50000,"21-12-2018"); //creating the object of sub
class employee.
System.out.println(e.toString());
Student st=new
Student("sofia","Kirlampudi",234234,"mail
address","Senior"); //creating the
object of subclass Student.
System.out.println(st.toString());
}
}
In the above code i have explained the relationship between super class and sub class, and how to call super class method using sub class object.
so,here the data members of super class are:
1.name, 2.address, 3.phone_number, 4.email_address
the data members of sub class Employee are:
1.Office 2.salary,3. date_hired.
the data members of sub class Student are:
1.Status
UML Diagram:
Visibility of Data:
- private
+public
#protected
~default
Diagram:
Hoping that the above answer will help you...Thank you...
Give an object that could be represented through super and sub classes? Give an example and...
1. When a sub class object is created, when is the call to the super class constructor made? How does a programmer call the super class constructor from the sub class? What do all classes indirectly extend? What methods does every class inherit from the Object class? 2. When writing methods in a sub class, how can those methods call the methods from the parent class? 3. Which class is more specific, a super class or a sub class? 4. ...
in BASIC/BEGINNER OBJECT ORIENTATED JAVA Please write code for the following program using comments explaining the code. (You can hand write this). Give a UML example illustrating AGGREGATION. Include classes, fields, methods, instance fields. USE ONE SUPER CLASS AND TWO SUB CLASSES. Include pcode for at least one method of each class. Explain the whole part relationship and if this a deep or shallow copy.
In c# So far, you have created object-oriented code for individual classes. You have built objects from these classes. Last week, you created a UML for new inherited classes and objects. Finally, you have used polymorphism. When you add abstraction to this mix, you have the “4 Pillars of OOP.” Now, you begin putting the pieces together to create larger object-oriented programs. Objectives for the project are: Create OO classes that contain inherited and polymorphic members Create abstracted classes and...
Java is an object-oriented programming language that enables us to define classes and to instantiate them into objects. These objects then call each other’s methods to implement the behavior of the application. The Unified Modeling Language (UML) is an object-oriented visual notation to document the design of object-oriented classes. For this discussion, you will practice designing a Java class called Course, drawing a UML class diagram for the Course class, and then implementing the Course class in Java code. Review...
The following is for java programming. the classes money date and array list are so I are are pre made to help with the coding so you can resuse them where applicable Question 3. (10 marks) Here are three incomplete Java classes that model students, staff, and faculty members at a university class Student [ private String lastName; private String firstName; private Address address; private String degreeProgram; private IDNumber studentNumber; // Constructors and methods omitted. class Staff private String lastName;...
1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram. Save your UML diagram and also export it as a PNG. B) Second, write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create...
Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes and Objects (15 Points) You will create 3 new classes for this project, two will be chosen (THE TWO CHOSEN ARE TENNIS SHOE AND TREE) from the list below and one will be an entirely new class you invent. Here is the list: Cellphone Clothes JuiceDrink Book MusicBand Bike GameConsole Tree Automobile Baseball MusicPlayer Laptop TennisShoe Cartoon EnergyDrink TabletComputer RealityShow HalloweenCostume Design First Create...
Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...
Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....
UML Class Diagram with Inheritance Objectives Use UML Correctly indicate inheritance Demonstrate permissions Understand inheritance relationships Labwork Please read all of the directions carefully. You will create a UML class diagram reflecting the class hierarchy for a fictional program that manages university personnel as constructed according to the graph displayed below. You will need to think about the attributes and behaviors that are unique to each class, and also those attributes and behaviors that are common amongst the subclasses and...