Question: EX1 Consider the following class: 1. Write its default constructor 2. Write a code to declare an object from this class using the default constructor
EX1
Consider the following class:
1. Write its default constructor
2. Write a code to declare an object from this class using the default constructor
( the code in java )
public class Dog{
String name;
String color;
void barking() {
}
{ void hungry() {
}
void sleeping() {
}
}
----------------------------------------------------------------------------------------------------------
EX2
Draw the UML diagram of the following class:
public class Employee {
String name;
double salary;
public Employee() {
}
public double getSalary() {
return this.salary:
}
public String getName() {
return this.name;
}
}
------------------------------------------------------------------
EX3
Write a program to print the area of a rectangle by creating a class named "Rectangle" with constructor having the two sides (width and height) as its parameters
Test the class by creating a main class which contains the main method O name the class "TestRectangle"
Use the Scanner library to take the two sides as inputs from the console.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
