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 4271810
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:29:33+00:00 2026-05-21T07:29:33+00:00

Right now I’m trying to implement this interface with an int which represents a

  • 0

Right now I’m trying to implement this interface with an int which represents a binary number.

I know I shouldn’t implementto string(); , but Let’s assume that I need to.

This is what I wrote so far:

public class IPAddressInt implements IPAddress {
private int ipAdress;

public IPAddressInt(int num1,int num2, int num3, int num4){
    String n1=Integer.toBinaryString(num1);
    String n2=Integer.toBinaryString(num2);
    String n3=Integer.toBinaryString(num3);
    String n4=Integer.toBinaryString(num4);
    
    String finalString=n1+n2+n3+n4;
    this.ipAdress=Integer.parseInt(finalString);
}

public String toString() {
    return this.toString();
    
    
}

when I’m tring to return this.ipAdress.toString(); or even ipAdress.toString()
the compiler says that it Cannot invoke toString() on the primitive type int,
and when I write only this.toString(); it works. why? I know that an int can be converted to a string, and how come the this works and the whole statement is not? shouldn’t it be the same? will I get what I want anyway?

Thank you.

  • 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-21T07:29:34+00:00Added an answer on May 21, 2026 at 7:29 am

    Calling this.toString() is just going to blow up – it’s calling the same method recursively, with no exit.

    The reason you can’t call toString directly on ipAddress is that int is a primitive type, and you can’t call methods on primitive types.

    To convert anything to a string, use String.valueOf(ipAddress). For int in particular, you could use Integer.toString(ipAddress).

    It’s not really clear why you’re doing the conversion to a binary string in the first place though… that doesn’t look like a good idea to me. Any reason why you’re not using

    ipAddress = (num1 << 24) | (num2 << 16) | (num3 << 8) | num4;
    

    (assuming each value is really in the range 0-255).

    I highly doubt that the binary representation is really want you want, particularly given the lack of padding, and that you’re then trying to parse it as a decimal number.

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

Sidebar

Related Questions

Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now I'm doing something like this: RewriteRule ^/?logout(/)?$ logout.php RewriteRule ^/?config(/)?$ config.php I
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
this is what i have right now Drawing an RSS feed into the php,
Right now I am trying to use selenium ide to write code that makes
Right now when i do something like this: use strict; use warnings; package My::Test;
Right now, I'm using this fashion: window.Foo = { alpha: function() {}, bravo: function(arg)
Right now, I keep all of my projects on my laptop. I'm thinking that
Right now, I'm particularly interested in reading the data from MP3 files (ID3 tags?),
Right now my ant task looks like. <javadoc sourcepath=${source} destdir=${doc}> <link href=http://java.sun.com/j2se/1.5.0/docs/api/ /> </javadoc>

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.