Link to home
Create AccountLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

when creating a instance to a class, do you have to include all the varaibles

I basically want to get a value from a function in Class B from Class A

I write a getter method in class B that returns my value.
In Class A, I do

b value = new b();
String k = a.getb();
System.out.println( k );

my question is my Class B has many variables in the constructor.  Example Class B(string, list, dialog, etc, etc, etc);
Do I have to include all those varaibles when all I really care about is just getting the value fro the method?
Avatar of for_yan
for_yan
Flag of United States of America image

If you use this constructor which has all these arguments - you have to have all of them in your new() statement. You can provide null or zero or any othe valuie but number of parameters should be the one contryctoir needs.
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jkteater

ASKER

You can have 2 constructors in one class?
Avatar of CEHJ
>>You can have 2 constructors in one class?

You can have as many as you want. Providing the value of field is available, you could even have a no-arg ctor:
public class B {
    public B(){} // no-arg ctor
...
}

Open in new window