0
Hey
Can non primitive variables be a instance variable?? in java
7 Respuestas
+ 5
Yes. I'm pretty sure it's an example of composition.
https://code.sololearn.com/c6qNZbsNJ7xA/?ref=app
+ 4
Hi Programmer</>
Just a tip!
Please keep your title relative to your problem. It will help users to understand what's the question without opening it. 😊
+ 3
Programmer</> If you want to do so, make the nonPrimitive object static. Without the static keyword, test is an instance variable (which belongs to the instance of the class and not the class itself) and cannot be invoked in a static method.
public class Program
{
private static nonPrimitive test = new nonPrimitive();
public static void main(String[] args) {
System.out.print(test.value);
}
}
+ 2
C++ python3 php
I don't see relation to your tags
+ 1
Sachin Artani Right bro👍
0
Fermi its means that we can create multiple objects of this nonprimitve variable
0
Fermi and why did u put (new nonPrimitive () ) inside Program () constructor.....??? and can we put new nonPrimitive () outside the constructor of Program () and inside Program class??