I had asked a question about implementing a class by subclass in Java previously and I found a different approach used.(different for me!) URL: here
public void paintComponent(Graphics g){
this line was confusing for me, for a class was passed as a parameter. Well, I thought of giving a try and understand before I asked here. Here's my code:
public class parameterObject{
String name;
int age;
public parameterObject(){}
public parameterObject(String inputName,int inputAge){
name = inputName;
age = inputAge;
}
public void testObject(){
System.out.println(name);
System.out.println(age);
}
}
and in the next class, I used a method to pass parameterObject
as a parameter (in bjueJ environment)
public void testFunction(parameterObject pO, int a){
pO.testObject();
}
when I called the method, testFunction(...)
It asked for parameter values and I entered "arpan",19 and 20
.
error: expected..
and then I tried using null
for the objectParameter and then the JVM threw nullPointException
error..
what was supposed to happen and what is lacking in my understanding? please help.