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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:48:26+00:00 2026-06-17T20:48:26+00:00

Here I have few Questions: 1)I tried to return a null value from a

  • 0

Here I have few Questions:

1)I tried to return a null value from a method,something like this(only when TypeCasted into object) :

 public static Object returns()
{
   return (Object)null ;
}

And stored the Object:

 ...main()..{
 Object obj=  returns();
 ...}

When i checked:

  if( obj.equals(obj))

Threw a NullPointerException

But,

 if(null==null)
 System.out.println("works");

Compiled and gave right output.Any reasons for this?

2) Also, when i tried:

 public static Object returns()
{
  return (Object)void ;
}

Gave me Syntax Error.Any reasons?

3) Can this behaviour be different in C/C++ ?Or any other OO Language?

  • 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-17T20:48:27+00:00Added an answer on June 17, 2026 at 8:48 pm

    You can not call equals on null instead you should use ==. Note that calling == and equals is not the same. == compares references while equals is a method which by convention compares values. As the null object has no value this has no meaning for it.

    Void is not a value in any language and so it can not be casted to anything(in this case Object).

    In C++ to return NULL you will have to return a pointer. To compare the returned object you will have to type something like:

     if( *obj == *obj)
    

    And again this will fail as obj is NULL. In any language I know you will have to do an explicit check for null before comparing.

    EDIT: come to think a bit what you try will work in ruby

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

Sidebar

Related Questions

I have tried solving this problem by posting other related questions here that focused
I have read quite a few selcet+update questions in here but cannot understand how
Here's the problem -- I have a few thousand small text snippets, anywhere from
Have a bit of confusion here. I added a few objects from a class
I have some code in my application that looks something like this: char *hash
I have a few classes as shown here public class TrueFalseQuestion implements Question{ static{
I am using T-SQL I have a few excel files located here: C:\MyFiles\ I
Sorrry guys, I'm stuck here. I have a few grids, I also have CollectionViewSource
Here is the problem: I have a WCF service and a few sites connecting
I have the following regular expression with which I match a few lines. Here

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.