forked from MLSA-Mehran-UET/Learn-to-code-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WrapperClass.java
59 lines (51 loc) · 1.58 KB
/
WrapperClass.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Java is not 100% OOP because it can have primitive type variables like int float etc
but wrappper class gives a solution. instead of creating primitive variables. we can store our
data into wrapper classes.
for eg
Integer is a wrapper class which stores int values . But since Integer is a class not primitive variabele
hence we can say that now every things is object
*/
package wrapper.pkgclass;
public class WrapperClass {
public static void main(String[] args) {
// static function present in each wraper class
// takes input as integer and saves as integer
// return reference of Integer class
Integer in= Integer.valueOf("88");
//similary
Float f=Float.valueOf("5.55");
//static funtion to convert string to corresponding types
int i=Integer.parseInt("22");
//similarly
double d=Double.parseDouble("4.3");
//instance function that returns value stored in Integer class
int a =in.intValue();
}
}
class Wrapperclass
{
public static void main(String args[])
{
// static function present in each wraper class
String a="123";
Integer i=Integer.parseInt(a); //creating a wrapper class object
//this will convert the string into the corresponding type
if(a.equals("123"))
{
System.out.println("Equals");
}
else
{
System.out.println("Not equals");
}
if(i==(123))
{
System.out.println("Print");
}
else
{
System.out.println("Not Print");
}
}
}