0

Help in variables

in this code.... public static class Cat { public Woman owner; } .. . a variable 'owner' is declared with Woman data type . but i have seen var declarations as like - int rate or char name and these storing integer and character value. . .. how can we declare a variable with Woman data type and what value will it store ?? https://code.sololearn.com/ccXcAlmtUqr9/?ref=app

13th Feb 2021, 2:10 PM
Shubham Yadav
Shubham Yadav - avatar
6 Antworten
+ 2
The variable will hold a reference to an object (instance) of the class specified as the variable's type e.g. a reference to a `Woman` object.
13th Feb 2021, 3:22 PM
Ipang
+ 4
maybe you want somthing like this? also I dont think static classes are the right choice unless you using static methods or fields. https://code.sololearn.com/cfaI8zQobx1p/?ref=app
13th Feb 2021, 8:02 PM
D_Stark
D_Stark - avatar
+ 2
It is very much possible since Java is OOP language. Everything except the primitive types are instance of a certain class. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
13th Feb 2021, 2:42 PM
Ipang
+ 1
Did you not have an instruction telling you what to do with the code? I see an instruction at line 10, but no detail on what is next step. I think you should try to consult the book/site where you found that task.
13th Feb 2021, 2:33 PM
Ipang
+ 1
Ok I got that . I read the link provided by u of primitive data types. But can u help me with this as which type of value does the variable will hold when declared with class name like int holds numeric value.
13th Feb 2021, 3:15 PM
Shubham Yadav
Shubham Yadav - avatar
0
What I want to know is that how can we use a class name as data type to declare a variable like used here - class name Woman used as data type for variable ' owner '
13th Feb 2021, 2:37 PM
Shubham Yadav
Shubham Yadav - avatar