首页 \ 问答 \ JVM将始终创建Object类的实例(Will JVM always create instance of Object class)

JVM将始终创建Object类的实例(Will JVM always create instance of Object class)

假设使用以下代码,JVM是否总是创建Object类的实例,因为Object是Java中所有类的父类。

class MyTestclass{

   void printMe(String name){
        System.out.println('I am '+name);
   }
   public static void main(String args[]){
        MyTestclass obj = new MyTestclass();
        obj.printMe("stackOverFlow.com");
   }
}

另一个班级说TestClass2

class TestClass2{

   void printMe(String name){
        System.out.println('I am '+name);
   }
   public static void main(String args[]){
        MyTestclass obj = new MyTestclass();
        TestClass2 obj2 = new TestClass2();
        obj.printMe("stackOverFlow.com");
        obj2.printMe("stackOverFlow.com");
   }
}

如果我运行这两个类,JVM是否会创建两个对象实例?


suppose with the following code, does JVM always create instance of Object class, since Object is parent for all the classes the in Java.

class MyTestclass{

   void printMe(String name){
        System.out.println('I am '+name);
   }
   public static void main(String args[]){
        MyTestclass obj = new MyTestclass();
        obj.printMe("stackOverFlow.com");
   }
}

Another class say TestClass2

class TestClass2{

   void printMe(String name){
        System.out.println('I am '+name);
   }
   public static void main(String args[]){
        MyTestclass obj = new MyTestclass();
        TestClass2 obj2 = new TestClass2();
        obj.printMe("stackOverFlow.com");
        obj2.printMe("stackOverFlow.com");
   }
}

Will JVM creates two object instances if i run these two classes?


原文:https://stackoverflow.com/questions/26159220
更新时间:2024-04-07 12:04

最满意答案

一个功能怎么样?

public static int getBit(byte b, int bit)
{
    int power = 1 << bit;
    return (b & power) ? 1 : 0;
}

public static void main(String[] args)
{
    for (int j = 0; j < 8; j++)
    {
        System.out.println(getBit(0x55, j));
    }
}

How about a function?

public static int getBit(byte b, int bit)
{
    int power = 1 << bit;
    return (b & power) ? 1 : 0;
}

public static void main(String[] args)
{
    for (int j = 0; j < 8; j++)
    {
        System.out.println(getBit(0x55, j));
    }
}

相关问答

更多
  • 向ncoghlan道歉: expanded_bits = [ 0b00000000000000000000000000000000, 0b00000000000000000000000011111111, 0b00000000000000001111111100000000, 0b00000000000000001111111111111111, 0b00000000111111110000000000000000, 0b0000000011111111000 ...
  • 如果您正在谈论单个字节,则表查找可能是最好的选择,除非由于某些原因您没有256字节可用。 If you are talking about a single byte, a table-lookup is probably the best bet, unless for some reason you don't have 256 bytes available.
  • 这应该完成这项工作: $bin = decbin(ord($char)); $bin = str_pad($bin, 8, 0, STR_PAD_LEFT); This should do the job: $bin = decbin(ord($char)); $bin = str_pad($bin, 8, 0, STR_PAD_LEFT);
  • 我敢打赌,有一个更聪明的方法来做到这一点,但它的工作原理: private string byteToBitsString(byte byteIn) { char[] bits = new char[8]; bits(0) = Convert.ToString((byteIn / 128) % 2); bits(1) = Convert.ToString((byteIn / 64) % 2); bits(2) = Convert.ToString((byteIn / 32) ...
  • 一个功能怎么样? public static int getBit(byte b, int bit) { int power = 1 << bit; return (b & power) ? 1 : 0; } public static void main(String[] args) { for (int j = 0; j < 8; j++) { System.out.println(getBit(0x55, j)); } } How about ...
  • 您需要使用位操作操作来提取值。 例如 int pressure = (byte[0]&0xff)<<16+(byte[1]&0xff)<<8+(byte[2]&0xff) (16和8可能需要12和4或0 4和12,具体取决于它的含义)。 您需要的操作是<<移位字节内的位,而&0xff将有符号的整数更改为有符号整数,然后再移位它。 否则标志位会弄乱。 You need to use bit manipulation operations to extract the values. For example ...
  • 访问位通常通过屏蔽和移位来完成。 对于掩模本身,您不需要考虑最高/最低有效位的位置。 位1具有掩码1,位2具有掩码2,位3具有掩码4等。 如果你想在任意硬件和任意每字节位设置的最低/最高位的位置n位,那么只有一种算法: /* set bit N */ extr <- 2^N do extr <- rot_right(extr) until (extr & 1) 如果最低有效位在最左侧内部存储,则该算法也将起作用,但它需要进行位旋转操作。 然后,您可以使用计数器确定LSB是最左侧还是最右侧。 通常(现在 ...
  • 要获得最后两位,请尝试使用value & 3而不是value % 100 。 ( value % 100取十进制除以100后的value的余数,而不是二进制)。然后需要将这两位移入最终字节中的适当位置。 像这样的东西: r = (pixels[n][0] & 3) << 4; g = (pixels[n][1] & 3) << 2; b = (pixels[n][2] & 3); a = (pixels[n][3] & 3) << 6; val = a | r | g | b; // ...
  • 好吧,我发现计算机采用数字2 0011 0010所以现在我得到了为什么它使用一个完整的字节,它使用ascii表,使用0011代表一个数字,然后是该数字的二进制代码,所以2到二进制会是0010但在其后面有0011,使得0011 0010总共为8位。 Ok I have found that the computer takes the number 2 as 0011 0010 so now I got why it uses a full byte it is using the ascii table t ...
  • 假设字节是你的字节[8]。 我们还要说字节是大端,意味着第一位是最重要的( http://en.wikipedia.org/wiki/Endianness ) 0 1 2 3 4 5 6 7 11111111 11111111 11112222 22222222 22222222 33333333 33333333 3333444B int first = bytes[0] << 12 + bytes[1] ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。