Null reference

11-30  Source: Network gathering  Views:0 

Advertisement
hi guys..!
plz can anyone explain the output of the code below...
public class AQuestion
public void method(Object o)
System.out.println("Object Version");
public void method(String s)
System.out.println("String Version");
public static void main(String args[])
AQuestion question = new AQuestion();
question.method(null);
thanx in advance....
regards,
j-c
In case over overloaded methods, Java wil try to find the best, and most excplicitly defined method. String is more explicit than Object, so that one is chosen. It is valid, since a String object CAN be null.
Following WILL print "object version", since int cannot be null:
public class AQuestion {
   public void method(Object o) {
      System.out.println("Object Version");
   public void method(int i) {
      System.out.println("int Version");
   public static void main(String args[]) {
      AQuestion question = new AQuestion();
      question.method(null);
}
Related articles
  • Dereferencing the NULL reference while saving a Survey 10-11

    While saving a survey first time, I am getting an error message "Dereferencing the NULL reference". More details as follows: Exception: Class CX_SY_REF_IS_INITIAL Program: CL_SVY_H_SVYDETAIL_IMPL=======CP Include: CL_SVY_H_SVYDETAIL_IMPL=======C

  • Problem with null reference 10-11

    Hey, I have a "Window" class wich extends JFrame and then creates a tabbedPane. In each of the tabs it's necessary to access to another class (Code). Each of the tabs follows something like this: public class Tab1 extends JPanel {    private Cod

  • EJB P.R.O.narrow method returns a null reference though object is valid 10-11

    All, I'm trying to deploy a simple stateless session bean to SUN server. The client code keeps failing because PortableRemoteObject.narrow returns null, even though the reference is located in JNDI tree. I read somewhere that turning on RMI stub gene

  • TypeError: Error #1009 - (Null reference error) With Flash. 11-30

    I am not an expert in flash, but i do work with AS and tweak Flash projects , though not having deep expertise in it. Currently i need to revamp a flash website done by one another guy, and the code base given to me, upon execution is throwing the fo

  • Storing null reference as 0 11-30

    I'm working with a schema that I cannot change and it doesn't allow nulls in id columns, they must be stored as 0. So there's an issue when I have a class A with a reference to class B, a.b. The table persisting A has a column bId, which would store

  • Object null reference error while creating Web applications, Service applications etc after restoring AD accounts 10-11

    Hi, The old Active Directory accounts of my server were removed, those accounts are used by some of the SharePoint sites. A new AD account was created and when I try to replace the old accounts with new I am facing issue. I am also unable to create n

  • Strange! null reference in a String witch shouldn't be null 11-30

    I have a bug that really I dont understand. I get un Id from a database with a select query. and i check that is correctly gotten. then i set this Id in a static attribute of a class. fro example: Test.setId(_id); when i want to insert this id in a s

  • Null reference 11-30

    hi guys..! plz can anyone explain the output of the code below... public class AQuestion public void method(Object o) System.out.println("Object Version"); public void method(String s) System.out.println("String Version"); public stati

  • Null reference exception using Microsoft.Unity on DisposeOfChildContainer() 11-30

    I am working on mvc application which also has webapi. Application is throwing System.NullReference Exception in production. (MVC 5, WebApi 2.0, .Net 4.5, Unity 3.0) Error message System.NullReferenceException: Object reference not set to an instance

  • Unit Testing, Null, and Warnings 10-11

    I have a Unit Test that includes the following lines: Dim nullarray As Integer()() Assert.AreEqual(nullarray.ToString(False), "Nothing") The variable "nullarray" will obviously be null when ToString is called (ToString is an extension

  • Difference between .equals("") and .equals(null) 10-11

    Can any one please tell me the difference between the following? String someString; someString = someMethod(someParameter); After the method call, if I am going for a check like this.. what will each check do? 1. if (someThing.equals(null)) 2. if (so

  • "Object reference not set to an instance of an object" when opening designer 10-11

    I have a Windows Forms project which was originally developed in Visual Studio 2010. I migrated the project to VS2013, and now every time I open the project's main form, the designer complains of a null reference. If I hit "Ignore and Continue",

  • Difference between vector obj.clear() and Vector obj = null 10-11

    What is the difference between clearing the Vector object with .clear() method and assigning null value to Vector object? As per memory point of view, is it advisable to first clear vector and then assaign it to null for garbage collection or it does

  • When primary table is also join table and you have NOT NULL constraints 10-11

    Hi, Me again. This is similar to the message titled "Problem with an optional 1 to 1 relationship modelled using a link table". Whats different about this case is we are dealing with a one to many relationship. Given this SQL: create table perso

  • String is not null forever? 10-11

    String a = ""; String b = new String(); a==null? false b==null? false why?you mean a.b are Strings with length 0 but they are exist so not equal Null?Not quite. a and b are variables. They hold references. Those references could be null (which m

  • Check for null value of an attribute 10-11

    Hi, I am reading an attribute using the get_attribute method of the element of a node. Depending on whether the value of this attribute is initial or not, I need to do some further processing. But the get_attribute method itself is giving an exceptio

  • Crystal report (crystalReportsViewer) crash with null pointer exception 10-11

    Hi, My application are simple : m_crystalReportsViewer.ViewerCore.ReportSource = report; but in throw exception null pointer when I call showDialog. I see in code, we have method ShowTabHeader. private void ShowTabHeader(bool isShow)     Grid child =

  • Best Practice question - null or empty object? 10-11

    Given a collection of objects where each object in the collection is an aggregation, is it better to leave references in the object as null or to instantiate an empty object? Now I'll clarify this a bit more..... I have an object, MyCollection, that

  • Object reference not set to an instance of an object error when generating a schema using flat file schema wizard. 10-11

    I have a csv file that I need to generate a schema for. I am trying to generate a schema using flat file schema wizard but I keep getting "Object reference not set to an instance of an object." error when I am clicking on the Next button after s

  • Null Pointer Exception in Stateless Session Beans(EJB 3.0) 10-11

    I am executing a simple HelloUser example i code session bean interface and implementing session bean class in the EJB project. package ejb3inaction.ejb; import javax.ejb.Remote; @Remote public interface HelloUser {