198k views
4 votes
Write the definitions of two classes Day and Night. Both classes have no constructors, methods or instance variables. Note: For this exercise, please do not declare your classes using the public visibility modifier.

1 Answer

4 votes

Answer:

class Day

{

}

class Night

{

}

Step-by-step explanation:

Given

Two classes named: Day and Night

Requirement: Both classes have no constructors, methods or instance variables. should not be declared using the public visibility modifier.

The syntax to define a class in object oriented programming is

modifier class classname {

// Constructor

constructor(variablename) { ......}

// Methods

methods() { ... }

...

}

Access modifiers (or access specifiers) are keywords in object-oriented languages that set the accessibility of classes, methods, and other members. Examples are private, public, protected, etc.

Going by the syntax above to define class Day

Day

private class Day{

// Constructor

constructor(duration)

{

this.duration = duration;

}

// Methods

CalculateDate() { ... }

}

But the question states that both classes have no constructors, methods or instance variables. should not be declared using the public visibility modifier.

So, class Day will be defined as follows

class Day

{

}

It could also be declared using visibility modifiers other than public modifier. So, class Day will be defined as follows

private class Day

{

}

and

protected class Day

{

}

Similarly, class Night can be defined as follows

class Night

{

}

private class Night

{

}

and

protected class Night

{

}

User Noumenal
by
5.1k points