public class test (
2. public static void main (String args[]) {
3. int i = 0xFFFFFFF1;
4. int j = ~i;
5.
6. }
7. )
What is the decimal value of j at line 5?
A. 0
B. 1
C. 14
D. –15
E. An error at line 3 causes compilation to fail.
F. An error at line 4 causes compilation to fail.
Answer: C
2. public static void main (String args[]) {
3. int i = 0xFFFFFFF1;
4. int j = ~i;
5.
6. }
7. )
What is the decimal value of j at line 5?
A. 0
B. 1
C. 14
D. –15
E. An error at line 3 causes compilation to fail.
F. An error at line 4 causes compilation to fail.
Answer: C
j为0xFFFFFFF1取反 为 0x0000000E 化成十进制为14
Long 1 = new Long (42);
Double d = new Double (42.0);
Which two expressions evaluate to True? (Choose Two)
A. (i ==1)
B. (i == d)
C. (d == 1)
D. (i.equals (d))
E. (d.equals (i))
F. (i.equals (42))
Answer: D, E可是我运行的结果是: public static void main(String[] args) {
// TODO Auto-generated method stub
Integer i = new Integer (42);
Long l = new Long (42);
Double d = new Double (42.0);
double d2=42.0;
if(i.equals(d2)){
System.out.println("i.equals(d2)");
}else{
System.out.println("!i.equals(d2)");
}
if(d.equals(i)){
System.out.println("d.equals(i)");
}else{
System.out.println("!d.equals(i)");
}
if(i.equals(42)){
System.out.println("i.equals(42)");
}
}
!i.equals(d2)
!d.equals(i)
i.equals(42)
Integer的equals方法:
public boolean equals(Object obj) {
if (obj instanceof Integer) {//要想equals,必须得是同一个类型
return value == ((Integer)obj).intValue();
}
return false;
}
Long的equals:
public boolean equals(Object obj) {
if (obj instanceof Long) {
return value == ((Long)obj).longValue();
}
return false;
}
Double的equals:
public boolean equals(Object obj) {
return (obj instanceof Double)
&& (doubleToLongBits(((Double)obj).value) ==
doubleToLongBits(value));
}
j为0xFFFFFFF1取反 为 0x0000000E 化成十进制为14。
public ButtonObject(String strName)
{
this(strName, strName);
}
package nc.ui.pub;import java.util.ArrayList;
import java.util.Vector;public class ButtonObject
{
private String m_strName;
private String m_strHint;
private int m_nPower;
private ButtonObject m_boParent;
private Vector m_vecChildren;
private boolean m_bEnabled;
private boolean m_bVisible;
private boolean bUnionFunc;
private ArrayList alUnionFuncbtn;
private boolean m_bPower;
private Object m_data;
private String m_internalTag;
private int m_intModifiers;
private boolean m_isCheckboxGroup;
private boolean m_isExclusiveMode;
private boolean m_isPowerContrl;
private boolean m_isSelected;
private boolean m_isSeperator;
private String m_strCode;
private String m_strDisplayHotkey;
private String m_strHotKey;
private String m_strTag; public ButtonObject(String strName)
{
this(strName, strName);
} public ButtonObject(String name, ButtonObject[] children)
{
this(name);
addChileButtons(children);
} public ButtonObject(String name, String hint)
{
this(name, hint, 0);
} public ButtonObject(String name, String hint, int power)
{
this.m_strName = null; this.m_strHint = null; this.m_nPower = 0; this.m_boParent = null; this.m_vecChildren = null; this.m_bEnabled = true; this.m_bVisible = true; this.bUnionFunc = false; this.m_bPower = true;
this.m_data = null; this.m_internalTag = null;
this.m_intModifiers = -1; this.m_isCheckboxGroup = false; this.m_isExclusiveMode = true; this.m_isPowerContrl = true; this.m_isSelected = false; this.m_isSeperator = false;
this.m_strCode = null;
this.m_strDisplayHotkey = null; this.m_strHotKey = null; this.m_strTag = null; this.m_strName = name;
this.m_strHint = hint;
this.m_nPower = power;
this.m_strCode = name;
this.m_internalTag = name + String.valueOf(Math.random());
} public void addChildButton(ButtonObject bo)
{
bo.setParent(this);
getChildren().addElement(bo);
} public ButtonObject[] getChildButtonGroup()
{
ButtonObject[] bos = new ButtonObject[getChildren().size()];
return ((ButtonObject[])getChildren().toArray(bos));
} public Vector getChildren()
{
if (this.m_vecChildren == null)
try {
this.m_vecChildren = new Vector();
} catch (Throwable e) {
//handleException(e);
} return this.m_vecChildren;
} public String getHint()
{
return this.m_strHint;
} public String getName()
{
return this.m_strName;
} public ButtonObject getParent()
{
return this.m_boParent;
} public int getPower()
{
return this.m_nPower;
}// private static void handleException(Throwable exception)
// {
// ClientEnvironment.getInstance().handleException(exception);
// } public boolean isEnabled()
{
return this.m_bEnabled;
} public boolean isVisible()
{
return this.m_bVisible;
} public void removeAllChildren()
{
getChildren().removeAllElements();
} public void removeChildButton(ButtonObject bo)
{
getChildren().remove(bo);
} public void setChildButtonGroup(ButtonObject[] bos)
{
Vector children = getChildren(); children.removeAllElements();
if (bos != null)
for (int i = 0; i < bos.length; ++i)
children.addElement(bos[i]);
} public void setEnabled(boolean b)
{
this.m_bEnabled = b;
} public void setHint(String strHint)
{
this.m_strHint = strHint;
} public void setName(String newvalue)
{
this.m_strName = newvalue;
} public void setParent(ButtonObject newvalue)
{
this.m_boParent = newvalue;
} void setPower(int nPower)
{
this.m_nPower = nPower;
} public void setVisible(boolean visi)
{
this.m_bVisible = visi;
} public ButtonObject(String name, String hint, int power, String code)
{
this.m_strName = null; this.m_strHint = null; this.m_nPower = 0; this.m_boParent = null; this.m_vecChildren = null; this.m_bEnabled = true; this.m_bVisible = true; this.bUnionFunc = false; this.m_bPower = true;
this.m_data = null; this.m_internalTag = null;
this.m_intModifiers = -1; this.m_isCheckboxGroup = false; this.m_isExclusiveMode = true; this.m_isPowerContrl = true; this.m_isSelected = false; this.m_isSeperator = false;
this.m_strCode = null;
this.m_strDisplayHotkey = null; this.m_strHotKey = null; this.m_strTag = null; this.m_strName = name;
this.m_strHint = hint;
this.m_nPower = power;
this.m_strCode = code;
this.m_internalTag = name + String.valueOf(Math.random());
} public void addChileButtons(ButtonObject[] aryBtns)
{
if (aryBtns != null) {
getChildren().removeAllElements();
for (int i = 0; i < aryBtns.length; ++i)
addChildButton(aryBtns[i]);
}
} public int getChildCount()
{
if (this.m_vecChildren == null)
return 0; return getChildren().size();
} public String getCode()
{
return this.m_strCode;
} public Object getData()
{
return this.m_data;
} public String getDisplayHotkey()
{
return this.m_strDisplayHotkey;
} public String getHotKey()
{
return this.m_strHotKey;
} public String getInternalTag()
{
return this.m_internalTag;
} public int getModifiers()
{
return this.m_intModifiers;
} public ButtonObject[] getSelectedChildButton()
{
ButtonObject[] bo = (ButtonObject[])null; if ((isCheckboxGroup()) && (getChildCount() > 0))
{
ArrayList list = new ArrayList();
ButtonObject[] ary = getChildButtonGroup();
for (int i = 0; i < ary.length; ++i)
{
if (ary[i].isSelected())
{
list.add(ary[i]);
}
}
if (list.size() > 0)
{
bo = new ButtonObject[list.size()];
list.toArray(bo);
}
}
return bo;
} public String getTag()
{
return this.m_strTag;
} public boolean isCheckboxGroup()
{
return this.m_isCheckboxGroup;
} public boolean isExclusiveMode()
{
return this.m_isExclusiveMode;
} public boolean isPower()
{
return this.m_bPower;
} public boolean isPowerContrl() {
return this.m_isPowerContrl;
} public boolean isSelected()
{
return this.m_isSelected;
} public boolean isSeperator()
{
return this.m_isSeperator;
} public void setCheckboxGroup(boolean isCheckBoxGroup)
{
this.m_isCheckboxGroup = isCheckBoxGroup;
} public void setCode(String newCode)
{
this.m_strCode = newCode;
} public void setData(Object newData)
{
this.m_data = newData;
} public void setDisplayHotkey(String newDisplayHotkey)
{
this.m_strDisplayHotkey = newDisplayHotkey;
} public void setExclusiveMode(boolean mode)
{
this.m_isExclusiveMode = mode;
} public void setHotKey(String newHotKey)
{
this.m_strHotKey = newHotKey;
} public void setModifiers(int newModifiers)
{
this.m_intModifiers = newModifiers;
} public void setPower(boolean newPower)
{
this.m_bPower = newPower;
} public void setPowerContrl(boolean isPowercontrl) {
this.m_isPowerContrl = isPowercontrl;
} public void setSelected(boolean isSelected)
{
this.m_isSelected = isSelected;
} public void setSeperator(boolean isSeperator)
{
this.m_isSeperator = isSeperator;
} public void setTag(String tag)
{
this.m_strTag = tag;
} public void setUnionFuncFlag(boolean bFlag)
{
this.bUnionFunc = bFlag;
} public boolean isUnionFunc() {
return this.bUnionFunc;
} public void addUnionfuncbtn(ButtonObject btnobj)
{
if (this.alUnionFuncbtn == null)
this.alUnionFuncbtn = new ArrayList(); this.alUnionFuncbtn.add(btnobj); } public ArrayList getUnionfuncbtn() {
return this.alUnionFuncbtn;
} public String toString() {
return this.m_strName;
}
}