Tìm lỗi sai về định nghĩa phương thức trong lớp sau: class MyClass { String method1() { return "A"; } void method() { } double method() { return 1.5; } method() { } } Select one:a. String method1(){return "A";}b. double method(){return 1.5;}c. void method(){}d. method(){}
Question
Tìm lỗi sai về định nghĩa phương thức trong lớp sau: class MyClass { String method1() { return "A"; } void method() { } double method() { return 1.5; } method() { } } Select one:a. String method1(){return "A";}b. double method(){return 1.5;}c. void method(){}d. method(){}
Solution
Lỗi sai nằm ở lựa chọn d. method(){}. Trong Java, mỗi phương thức cần phải có một kiểu trả về rõ ràng, nhưng phương thức này không có kiểu trả về nào được chỉ định.
Similar Questions
class MyClass { String method1() { return "A"; } void method() { } double method() { return 1.5; } method() { } } Select one:a. String method1(){return "A";}b. double method(){return 1.5;}c. void method(){}d. method(){}
Giả sử 2 lớp MyClass1 và MyClass2 sau đây được khai báo trong cùng một package là com.poly. Hãy chọn câu lệnh phát sinh lỗi lúc dịch: package com.poly class MyClass1{ public void method1(){…} private void method2(){…} void method3(){…} } class MyClass2{ void method(){ MyClass1 o1 = new MyClass1(); o1.method1(); o1.method2(); o1.method3(); } } o1.method1(); o1.method2(); MyClass1 o1 = new MyClass1(); o1.method3();
Điền phương thức phù hợp vào vị trí <> để ghi đè lên phương thức của lớp cha? public class Parent{ public void method(int x){…} } public class Child extends Parent{ <> } public void method(){…} public void method(int y){…} public void method(int x, String s){…} public void method(double x){…}
The method with the declaration public static char procedure(double d) has a method type of _____. a. public b. static c. char d. double
One or more method can be declared in a class.*
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.