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

  • Home
  • SEARCH
  • 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 8947519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:46:53+00:00 2026-06-15T12:46:53+00:00

Possible Duplicate: Absence of property syntax in Java See the following situation: class Test

  • 0

Possible Duplicate:
Absence of property syntax in Java

See the following situation:

class Test extends Object {
    private int x;
    public getX() {return x;}
    public setX(int _x) {x = _x;}
}

As you can see, nothing special. However, I’d like to know if it’s possible to keep that “private x” in a way that someone using the class don’t need to use getX(), in other words, if I could map some variable that automatically called the gets and sets.

Something like the “property” in Delphi. It’d prevent the need of using setX() and getX() in a complex expression and would ease the understanding of who reads the expression.

For example, suppose another identifier xx and yy could be used in place of the get and set methods. See:

import Test;
public static void main(String[] args) {
    new Test() {
        setX(10);
        setY(20);
        int z = getX() * getY() + (getY() * getY());
        System.out.println("%d", z);
    }
    // would be like this
    new Test() {
        xx = 10;
        yy = 20;
        int z = xx * yy + (yy * yy); // xx would access the method getX() automatically
        System.out.println("%d", z);
    }
}

I hope you guys got what I mean here.

EDIT:

Rolly crepe! That’s a lot of answers! Thank you very much, everyone.

  • 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-06-15T12:46:55+00:00Added an answer on June 15, 2026 at 12:46 pm

    You can’t.

    That’s why we talk in “encapsulation”. Only if you change or modify from private to something else or if you use reflection (what would make it even more complicated).

    I don’t see any problem in using the famous getters and setters.

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

Sidebar

Related Questions

Possible Duplicate: Is Java pass-by-reference? I found an unusual Java method today: private void
Possible Duplicate: Java Wait and Notify: IllegalMonitorStateException What is the problem with private final
Possible Duplicate: Absence of typeof operator in C++03? Is it possible to use templates
Possible Duplicate: Why should the implementation and the declaration of a template class be
Possible Duplicate: Can you write object oriented code in C? Hi, can someone point
Possible Duplicate: C++ convert int and string to char* Hello, i am making a
Possible Duplicate: Why Option[T]? Reference types provide the special value null meaning "absence of
Possible Duplicate: How can a Java program use files inside the .jar for read
Possible Duplicate: Arithmetic operator overloading for a generic class in C# Here is the
Possible Duplicate: Cyclic module dependencies and relative imports in Python Consider the following example

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.