Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7041373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:02:10+00:00 2026-05-28T02:02:10+00:00

I wrote my class with its private variables and then I wrote the accessor

  • 0

I wrote my class with its private variables and then I wrote the accessor and mutator methods needed to access those variables, but that does not work when I run it after writing the main class. Why does that happening ?check my code here :

public class DateTest{
    public static void main (String [] args){

        Date d1 = new Date();
        Date d2 = new Date();

        d1.month = "February ";
        d1.day = 13;
        d1.year = 1991;

        d2.month = "July";
        d2.day = 26;
        d2.year = 1990;

        d1.WriteOutput();
        d2.WriteOutput();
        }
    }


      class Date {

private String month;
private int day;
private int year;

public String getMonth(){
    return month;
                     }
public int getDay(){
    return day;
                   }
public int getYear(){

    return year;    }

public void setMonth(String m){
    if (month.length()>0)
        month = m;
                      }
public void setDay(int d){
    if (day>0)
     day = d;       }
public void setYear(int y){
     if (year>0)
     year = y;
                          }

   public void WriteOutput(){
    System.out.println("Month " + month + "Day "+ day + " year" + year);
    }
    }

Please guys just be patient with me, I’m really a “novice” programmer

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:02:11+00:00Added an answer on May 28, 2026 at 2:02 am

    Java has no syntactic sugars like C# and won’t allow you to do calls in from object.property even though you have provided the access methods. Properties are purely a design pattern and are not refleted in syntax of a language itself.

    You need to call them explicitly like d1.setMonth("February "); and String val = d1.getMonth();.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We wrote a small Windows class library that implements extension methods for some standard
I have a class called Employee with its 2 private variables and also contains
I wrote a managed C++ class that has the following function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)
I wrote a script that is using the FilterIterator class that comes from the
i wrote this code: class Generate{ private $canvas; function __construct($width, $height){ $this->canvas = imagecreatetruecolor($width,
Here is a related manager I wrote: class PortfolioItemManager(models.Manager): use_for_related_fields = True def extended(self):
Okay, so i have this code i wrote: class Connection { public static StreamWriter
I recently wrote a class for an assignment in which I had to store
I wrote the following class for producing monitoring output within an extra window. Unfortunately
I wrote an abstraction class for a math object, and defined all of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.