1. class A { 2. protected int method1(int a, int b) { return 0; } 3. } Which two are valid in a clas
2015-01-14 13:35
555 查看
QUESTION NO: 3
1. class A {
2. protected int method1(int a, int b) { return 0; }
3. }
Which two are valid in a class that extends class A? (Choose two)
A. public int method1(int a, int b) { return 0; }
B. private int method1(int a, int b) { return 0; }
C. private int method1(int a, long b) { return 0; }
D. public short method1(int a, int b) { return 0; }
E. static protected int method1(int a, int b) { return 0; }
publicclass B extends A{
/**
*@paramargs
*/
//can not reduce the visibility of the inherited method from A
//即不能够使从类A中继续来的方法的可见性降低
//private int method1(int a, int b) { return 0; }
//This static method cannot hide the instance method from A
//静态方法不能够隐藏继承于A的实例
//static protected int method1(int a, int b) { return 0; }
//返回类型与A中的该方法不一致
//public short method1(int a, int b) { return 0; }
/**
*总结:类的继承中,如果要想重载父类的方法,必须要和父类中的返回类型、可见性等等都要操作一致
*否则,程序就会报错。一定遵守子类要遵从于父类的原则
*而我选择的答案居然是privateintmethod1和staticprotectedint
*我选择第一个的错误理由是:因为原来为保护的,如果我这里设为public,那么就扩展了其原来的可见性
*本来原来就是对包外不可见的,现在变成对包外可见的了,所以就选择的是private
*选择第二个的错误理由是:都是保护的,这里只是变成了静态的而已
*/
//这里是写了一个重载方法,因为参数类型不一致,不会报错
privateint method1(int a, long b)
{ return 0; }
//可见性可以增大,但是不能够缩小,正确
publicint method1(int a, int b)
{ return 0; }
publicstaticvoid main(String[]
args) {
// TODO Auto-generated
method stub
}
}
1. class A {
2. protected int method1(int a, int b) { return 0; }
3. }
Which two are valid in a class that extends class A? (Choose two)
A. public int method1(int a, int b) { return 0; }
B. private int method1(int a, int b) { return 0; }
C. private int method1(int a, long b) { return 0; }
D. public short method1(int a, int b) { return 0; }
E. static protected int method1(int a, int b) { return 0; }
publicclass B extends A{
/**
*@paramargs
*/
//can not reduce the visibility of the inherited method from A
//即不能够使从类A中继续来的方法的可见性降低
//private int method1(int a, int b) { return 0; }
//This static method cannot hide the instance method from A
//静态方法不能够隐藏继承于A的实例
//static protected int method1(int a, int b) { return 0; }
//返回类型与A中的该方法不一致
//public short method1(int a, int b) { return 0; }
/**
*总结:类的继承中,如果要想重载父类的方法,必须要和父类中的返回类型、可见性等等都要操作一致
*否则,程序就会报错。一定遵守子类要遵从于父类的原则
*而我选择的答案居然是privateintmethod1和staticprotectedint
*我选择第一个的错误理由是:因为原来为保护的,如果我这里设为public,那么就扩展了其原来的可见性
*本来原来就是对包外不可见的,现在变成对包外可见的了,所以就选择的是private
*选择第二个的错误理由是:都是保护的,这里只是变成了静态的而已
*/
//这里是写了一个重载方法,因为参数类型不一致,不会报错
privateint method1(int a, long b)
{ return 0; }
//可见性可以增大,但是不能够缩小,正确
publicint method1(int a, int b)
{ return 0; }
publicstaticvoid main(String[]
args) {
// TODO Auto-generated
method stub
}
}
相关文章推荐
- Question 37: In C++, which of the following statements regarding the code below are valid?
- 2.Which two statements are true about the Automatic Workload Repository (AWR)
- Which two are the uses of the ASM metadata backup and restore (AMBR) feature?
- This is probably a good time to review the order in which SELECT statement clauses are to be specified. Table 10.2 lists all the clauses we have learned thus far, in the order they must be used.
- Exception之The valid characters are defined in RFC 7230 and RFC 3986
- 异常:Invalid character found in the request target. The valid characters are defined in RFC 3986
- Hashtable and HashMap are two hash based collection in Java and used to store objects as key value p
- 4.Which two statements are true regarding single row functions? (Choose two.)
- Exception之The valid characters are defined in RFC 7230 and RFC 3986
- The valid characters are defined in RFC 7230 and RFC 3986错误
- 053-4 Which two statements about the SQL Management Base (SMB) are true? (Choose two.)
- The valid characters are defined in RFC 7230 and RFC 3986
- struts2 json注解 时 报错:The Result type [json] which is defined in the Result annotation on the clas
- The DCOM settings which are independent of whether the PC is in a work group or in a domain
- The valid characters are defined in RFC 7230 and RFC 3986 错误
- The valid characters are defined in RFC 7230 and RFC 3986
- Tomcat 报 The valid characters are defined in RFC 7230 and RFC 3986
- invalid character found in the request target the valid characters are defined in rfc 7230 and rfc
- 117.Which statements are true regarding the WHERE and HAVING clauses in a SELECT statement?
- 174 Using the LIST command in Recovery Manager (RMAN), which two pieces of information from the RMAN