Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wrapper object

 
saran bala
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please explain the reason?

public class Test12{
public static void main(String a[]){
byte b = 100;
Byte b1= new Byte(100);
Byte b2 = new Byte(b);
System.out.println(b1 == b2);
System.out.println(b1.equals(b2));
}
}
What is output?

Answer:Complier error
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15485
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try compiling it yourself. What error does the compiler give you exactly? Read the error message carefully and try to understand what it means.
 
Yogesh Baraskar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Byte b1= new Byte(100);
literals like 100 are of integer type by default.

To create a Byte object using new you should pass a byte

Try this
Byte b1= new Byte((byte)(100));
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic