现有如下代码, 请分两行写出其运行结果。 class People(object): def __init__(self): print("__init__") def __new__(cls, *args, **kwargs): print("__new__") return object.__new__(cls, *args, **kwargs) People() 知识点:类的定义和使用

题目

现有如下代码, 请分两行写出其运行结果。 class People(object): def __init__(self): print("__init__") def __new__(cls, *args, **kwargs): print("__new__") return object.__new__(cls, *args, **kwargs) People() 知识点:类的定义和使用


相似考题
参考答案和解析
B
更多“现有如下代码, 请分两行写出其运行结果。 class People(object): def __init__(self): print("__init__") def __new__(cls, *args, **kwargs): print("__new__") return object.__new__(cls, *args, **kwargs) People() 知识点:类的定义和使用”相关问题
  • 第1题:

    现有:classParserextendsUtils{publicstaticvoidmain(String[]args){System.out.print(newParser().getInt("42"));}intgetInt(Stringarg){returnInteger.parseInt(arg);}}classUtils{intgetInt(Stringarg)throwsException{return42;}}结果为()

    A.42

    B.编译失败。

    C.无输出结果。

    D.运行时异常被抛出。


    参考答案:A

  • 第2题:

    阅读下列代码 public class Test { public static void main(String args[]) { String s = "Test"; switch (s) { case "Java": System.out.print("Java"); break; case "Language": System.out.print("Language"); break; case "Test": System.out.print("Test"); break; } } } 其运行结果是( )。

    A.Java

    B.Language

    C.Test

    D.编译出错


    正确答案:D
    解析:switch语句根据其后表达式的值从多个分支中选择一个来执行,表达式只能返回int、byte、short和char类型。

  • 第3题:

    给定以下JAVA代码,这段代码编译运行后输出的结果是( )

    publicclassTest{

    publicstaticintaMethod(inti)throwsException{

    try{

    returni/10;

    }catch(Exceptionex){

    thrownewException("exceptioninaaMothod");

    }finally{

    System.out.print("finally");

    }

    }

    publicstaticvoidmain(String[]args){

    try{

    aMethod(0);

    }catch(Exceptionex){

    System.out.print("exceptioninmain");

    }

    System.out.print("finished");

    }

    }

    A、finallyexceptioninmainfinished

    B、exceptioninmainfinally

    C、finallyfinished

    D、finallyexceptioninmainfinished


    正确答案:C

  • 第4题:

    现有:  class Parser extends Utils  { public static void main (String[]  args)    {     try{System.out.print (new Parser().getlnt("42"));      } catch (Exception e)    {      System.out.println("Exc");  }      }  int getlnt (String arg) throws Exception  {      return Integer.parselnt (arg);      }       class Utils  {  int getlnt (String arg)    {return 42;  }      }      结果为()    

    • A、 42
    • B、 Exc
    • C、 42Exc
    • D、编译失败

    正确答案:D

  • 第5题:

    class BitStuff {   BitStuff go() { System.out.print("bits "); return this; }   }   class MoreBits extends BitStuff {   MoreBits go() { System.out.print("more "); return this; }   public static void main(String [] args) {   BitStuff [] bs = {new BitStuff(), new MoreBits()};   for( BitStuff b : bs)   b.go();   }   }   结果为:()  

    • A、bits bits
    • B、bits more
    • C、more more
    • D、编译失败

    正确答案:B

  • 第6题:

    现有:   class Thread2 implements Runnable {   void run() {   System.out.print("go ");   }   public static void main(String [] args) {   Thread2 t2 = new Thread2();   Thread t = new Thread(t2);   t.start();   }   }   结果为:()

    • A、 go
    • B、 编译失败
    • C、 代码运行,无输出结果
    • D、 运行时异常被抛出

    正确答案:B

  • 第7题:

    现有:  class Birds {  public static void main (String  []  args)  {   try {  throw new Exception () ;    } catch (Exception e) {   try {   throw new Exception () ;  }  catch  (Exception e2)  {  System.out.print ("inner           "); }   System. out.print ( "middle" ) ;    }  System.out.print ("outer") ;    }    }  结果是()

    • A、 inner outer
    • B、 middle outer
    • C、 inner middle outer
    • D、.编译失败

    正确答案:C

  • 第8题:

    现有:  class Output  {  public static void main (String[]  args)    {      int i=5:  System.out.print( "4"+i+"");      System.out.print (i+5+"7");     System.out.println  (i+"8");      }      }      结果为:()     

    • A、  99722
    • B、  955758
    • C、  4510758
    • D、  459722

    正确答案:C

  • 第9题:

    单选题
    class Parser extends Utils {  public static void main(String [] args) {   System.out.print(new Parser().getInt("42"));  }  int getInt(String arg) {  return Integer.parseInt(arg);  }  }  class Utils {  int getInt(String arg) throws Exception { return 42; }  }  结果为:()
    A

    42

    B

    编译失败

    C

    无输出结果

    D

    运行时异常被抛出


    正确答案: A
    解析: 暂无解析

  • 第10题:

    单选题
    现有  class Beverage {  Beverage ()  {  System.out.print ("beverage ");  }        }  class Beer extends Beverage {  public static void main{string [] args) {        Beer b = new Beer (14) ;       }  public int Beer(int x) {       this () ;  System.out.print ("beerl") ;      }  public Beer() { System.out.print("beer2 "); }     }  结果是什么?()
    A

    beerl beverage

    B

    beer2 beverage

    C

    beverage beer2 beerl

    D

    编译失败


    正确答案: B
    解析: 暂无解析

  • 第11题:

    单选题
    现有:  class Cat {  Cat(int c) { System.out.print("cat" + c + " "); }  }  class SubCat extends Cat {  SubCat(int c) { super(5); System.out.print("cable "); }  SubCat() { this(4); }  public static void main(String [] args) {  SubCat s = new SubCat();  }  } 结果为:()
    A

    cat5

    B

    cable

    C

    cable cat5

    D

    cat5 cable


    正确答案: C
    解析: 暂无解析

  • 第12题:

    单选题
    现有:  class Parser (类)extends(继承) Utils {   public static void main(String [] args) {   System.out.print(输出打印)(new Parser().getInt("42"));  }   int getInt(String arg) {   return Integer.parseInt(arg);    }   }   class Utils {   int getInt(String arg) throws Exception { return 42; }  }   结果为:()
    A

     42

    B

     编译失败。

    C

     无输出结果。

    D

     运行时异常被抛出。


    正确答案: C
    解析: 暂无解析

  • 第13题:

    下列代码的执行结果是( )。 public class test3{ public static void main (string args[]){ System.out.print(100%3); System.out.print(","); System.out.println( 100%3.0); } }

    A.1,1

    B.1,1.0

    C.1.0,1

    D.1.0,1.0


    正确答案:B

  • 第14题:

    阅读下列代码 public class Test2005{ public static void main(String args[]){ String s="Test"; switch(s){ case"Java":System.out.print("Java"); break; case"Language":System.out.print("Lan- guage"); break; case"Test":System.out.print("Test"); break; } } } 其运行结果是( )。

    A.Java

    B.Language

    C.Test

    D.编译时出错


    正确答案:D
    D。【解析】本题考查switch语句的用法。switch语句是多分支语句,即根据表达式的值来执行多个操作中的一个。在switch语句中,”表达式”的返回值类型必须是这几种类型之一:int、byte、char、short。本题中,switch的表达式s是一个字符串Strin9类型的值,它不是int、byte、char、short中的任意一个。因此表达式s的类型不对,编译时出错。

  • 第15题:

    下面程序的运行结果为( )。a=10def setNumber(): a=100setNumber()print(a)

    A.10

    B.100

    C.10100

    D.10010


    正确答案:A

  • 第16题:

    现有:   class ThreadExcept implements Runnable {   public void run() { throw new RuntimeException("exception "); }   public static void main(String [] args) {   new Thread(new ThreadExcept()).start();   try {   int x = Integer.parseInt(args[0]);   Thread.sleep(x);   System.out.print("main ");  } catch (Exception e) { }  }   }   和命令行:  java ThreadExcept 1000   哪一个是结果?() 

    • A、 main
    • B、 编译失败
    • C、 代码运行,但没有输出
    • D、 main java.lang.RuntimeException: exception

    正确答案:D

  • 第17题:

    如果想使用Python实现一个单例模式,有哪几种可能的做法?()

    • A、使用__new__方法
    • B、使用__init__方法
    • C、封装一个判断装饰器
    • D、使变量作为moduleimport进来

    正确答案:A,C,D

  • 第18题:

    现有:  class Guy {String greet()    {return "hi";  }  }  class Cowboy extends Guy  (  String greet()    (  return "howdy  ¨;    )  )  class Surfer extends Guy  (String greet()    (return "dude! ";)) class Greetings  {  public static void main (String  []  args)    {  Guy  []  guys =  ( new Guy(), new Cowboy(), new Surfer()  );  for (Guy g:  guys) System.out.print (g.greet()};  }  }  结果为:() 

    • A、 hi howdy dude!
    • B、运行时异常被抛出。
    • C、第7行出现一个错误,编译失败。
    • D、第8行出现一个错误,编译失败。

    正确答案:A

  • 第19题:

    class Parser extends Utils {  public static void main(String [] args) {   System.out.print(new Parser().getInt("42"));  }  int getInt(String arg) {  return Integer.parseInt(arg);  }  }  class Utils {  int getInt(String arg) throws Exception { return 42; }  }  结果为:() 

    • A、42
    • B、编译失败
    • C、无输出结果
    • D、运行时异常被抛出

    正确答案:A

  • 第20题:

    单选题
    现有:   class Parser extends Utils {   public static void main(String [] args) {     System.out.print(new Parser().getInt("42"));    }   int getInt(String arg) {  return Integer.parseInt(arg);  }    }   class Utils {     int getInt(String arg) throws Exception { return 42; }    }    结果为()
    A

     42

    B

     编译失败。

    C

     无输出结果。

    D

     运行时异常被抛出。


    正确答案: D
    解析: 暂无解析

  • 第21题:

    单选题
    现有:   class Thread2 implements Runnable {   void run() {   System.out.print("go ");   }   public static void main(String [] args) {   Thread2 t2 = new Thread2();   Thread t = new Thread(t2);   t.start();   }   }   结果为:()
    A

     go

    B

     编译失败

    C

     代码运行,无输出结果

    D

     运行时异常被抛出


    正确答案: C
    解析: 暂无解析

  • 第22题:

    单选题
    现有  class Parser extends Utils {  public static void main (String  []  args)  {  try  {  System.out.print (new Parser () .getlnt ("42"))       }  catch (Exception e) {  System.out.println ("Exc") ;  }      }  int getlnt (String arg)  throws Exception  {     return Integer.parselnt (arg) ;      }      }  class Utils {  int getlnt ()  {  return 42;  }     }  结果是什么?()
    A

     42Exc

    B

     Exc

    C

     42

    D

    编译失败


    正确答案: C
    解析: 暂无解析

  • 第23题:

    单选题
    现有:  class Guy {String greet()    {return "hi";  }  }  class Cowboy extends Guy  (  String greet()    (  return "howdy  ¨;    )  )  class Surfer extends Guy  (String greet()    (return "dude! ";)) class Greetings  {  public static void main (String  []  args)    {  Guy  []  guys =  ( new Guy(), new Cowboy(), new Surfer()  );  for (Guy g:  guys) System.out.print (g.greet()};  }  }  结果为:()
    A

     hi howdy dude!

    B

    运行时异常被抛出。

    C

    第7行出现一个错误,编译失败。

    D

    第8行出现一个错误,编译失败。


    正确答案: A
    解析: 暂无解析

  • 第24题:

    单选题
    下列程序的运行结果是(  )。class Shape{ public Shape(){ System.out.print("Shape"); }}class Circle extends Shape{ public Circle(){ System.out.print("Circle"); }}public class Test{ public static void main(String[]args){ Shape d=new Circle(); }}
    A

    Shape

    B

    Circle

    C

    ShapeCircle

    D

    程序有错误


    正确答案: B
    解析:
    继承是面向对象编程的一个主要优点之一,它对如何设计Java类有着直接的影响。该程序首先编写了一个Shape的类,然后又编写一个类Circle去继承Shape类。由于子类拥有父类所有的属性和方法,所以输出的是ShapeCircle。