Knowee
Questions
Features
Study Tools

3.Chọn đáp án đúng.class Run1 {void display(){ System.out.println("Run1");}}class Run2 extends Run1{void display2(){ System.out.println("display2");}}public class test {public static void main(String[] args) { Run2 run = new Run2(); run.display();}}doneRun1Run2Run1Run2Lỗi biên dịch

Question

3.Chọn đáp án đúng.class Run1 {void display(){ System.out.println("Run1");}}class Run2 extends Run1{void display2(){ System.out.println("display2");}}public class test {public static void main(String[] args) { Run2 run = new Run2(); run.display();}}doneRun1Run2Run1Run2Lỗi biên dịch

🧐 Not the exact question you are looking for?Go ask a question

Solution

Đáp án đúng là "Run1".

Giải thích: Trong đoạn mã trên, chúng ta có hai lớp là Run1 và Run2 (lớp Run2 kế thừa từ lớp Run1). Trong lớp Run1, chúng ta có phương thức display() in ra "Run1". Trong lớp Run2, chúng ta có phương thức display2() in ra "display2".

Trong hàm main, chúng ta tạo một đối tượng của lớp Run2 và gọi phương thức display(). Vì lớp Run2 kế thừa từ lớp Run1, nên nó có thể gọi phương thức display() của lớp Run1. Do đó, đoạn mã trên sẽ in ra "Run1".

This problem has been solved

Similar Questions

7.Cho biết kết quả hiển thị của đoạn mã sau:class Run1 {void display(){System.out.println("Run1");}}class Run2 extends Run1{@Overridevoid display(){System.out.println("Run2");}}class test {public static void main(String[] args) {Run1 run = new Run1();run.display();}}doneRun1Run2Run1Run2Compilation fails

Cho biết kết quả hiển thị của đoạn mã sau:class TestA{public void start(){System.out.println("TestA");}}class TestB extends TestA{public void start(){System.out.println("TestB");}public static void main(String[] args){((TestA)new TestB()).start();}}doneTestATestBLỗi biên dịchLỗi thực thi

Find the output: abstract class One { int i; abstract void display(); } class Two extends One { int j; void display() { System.out.println(j); } } class AbstractDriver { public static void main(String args[]) { Two obj = new Two(); obj.j=2; obj.display(); } }

elect the correct answerWhat will be the output of the following Java program? class parent { int a; public void display() { System.out.println(a); } } class child extends parent { int b; public void display() { System.out.println(b); } } class Dynamic_dispatch { public static void main(String args[]) { child obj2 = new child(); obj2.a = 2; obj2.b = 4; parent r; r = obj2; r.display(); } }Options6428

the correct answerWhat will be the output of the given Java program? abstract class java {    int x;    abstract void display(); }     class method extends java {     int y;     void display() {        System.out.println(y);     } }     class Abstract_demo {     public static void main(String args[]) {         method obj = new method();         obj.y = 1;         obj.display();         } }Options0Runtime Error1Compilation Error

1/3

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.