Câu hỏi về kế thừa Java

Câu hỏi về kế thừa Java

1st - 12th Grade

15 Qs

quiz-placeholder

Similar activities

Quiz MPC 2020

Quiz MPC 2020

KG - 1st Grade

18 Qs

Basic Vocabulary Test 18 P.5

Basic Vocabulary Test 18 P.5

5th Grade

13 Qs

Chinese class rules

Chinese class rules

7th Grade

10 Qs

Getting to know about you

Getting to know about you

5th Grade

15 Qs

porps 8b

porps 8b

8th Grade

11 Qs

Could you work at the SCP foundation?

Could you work at the SCP foundation?

KG - Professional Development

13 Qs

Getting to Know Sir Lardi More:D

Getting to Know Sir Lardi More:D

10th Grade

10 Qs

wiedza o league of legends

wiedza o league of legends

9th - 10th Grade

10 Qs

Câu hỏi về kế thừa Java

Câu hỏi về kế thừa Java

Assessment

Quiz

Fun

1st - 12th Grade

Practice Problem

Medium

Created by

Kiều Thị

Used 1+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

15 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Kết quả của đoạn mã sau in ra như thế nào?

class Employee {

    float salary = 1000;

}

class Programmer extends Employee {

    int bonus = 150;

}

public class InheritanceSample1 {

    public static void main(String args[]) {

        Programmer p = new Programmer();

        System.out.println("Programmer salary is: " + p.salary);

        System.out.println("Bonus of Programmer is: " + p.bonus);

    }

}

Programmer salary is: 1000.0 Bonus of Programmer is: 150

Lỗi biên dịch do không thể khai báo Programmer p = new Programmer();

Lỗi dòng in p.salary do Programmer không có salary

Programmer salary is: 1000.0 Bonus of Programmer is: 150.0

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Kết quả của đoạn mã sau in ra như thế nào?

class Animal {

    void eat() {

        System.out.println("eating...");

    }

}

class Dog extends Animal {

    void bark() {

        System.out.println("barking...");

    }

}

public class TestInheritance1 {

    public static void main(String args[]) {

        Animal d = new Dog();

        d.bark();

        d.eat();

    }

}

eating... barking...

Lỗi biên dịch do không thể khai báo Animal d = new Dog();

barking... eating...

Lỗi biên dịch dòng d.bark

3.

MULTIPLE SELECT QUESTION

30 sec • 1 pt

Kết luận nào sau đây đúng:

class A {

    private int data = 40;

    private void msg() {

        System.out.println("Hello Java");

    }

}

public class Simple {

    public static void main(String args[]) {

        A obj = new A();

        System.out.println(obj.data);

        obj.msg();

    }

}

40 Hello Java

Lỗi biên dịch dòng obj.data

Lỗi biên dịch dòng obj.msg()

Không có kết luận đúng

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Kết luận nào sau đây đúng:

package com.codegym.demo1;

class A {

    void msg() {

        System.out.println("Hello");

    }

}

package com.codegym.demo2;

import com.codegym.demo1;

public class B {

    public static void main(String args[]) {

        A obj = new A(); 

        obj.msg();  

    }

}

Kết quả là Hello

Lỗi biên dịch dòng A obj = new A();

Lỗi biên dịch dòng obj.msg();

Không có kết luận đúng

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Kết luận nào sau đây đúng:

package com.codegym.demo1;

public class A {

    void msg() {

        System.out.println("Hello");

    }

}

package com.codegym.demo2;

import com.codegym.demo1;

public class B extends A {

    public static void main(String args[]) {

        A obj = new A(); 

        obj.msg();  

    }

}

Kết quả là Hello

Lỗi biên dịch dòng A obj = new A();

Lỗi biên dịch dòng obj.msg();

Không có kết luận đúng

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Kết quả của chương trình in ra là gì?

class Vehicle {

    int speed = 50;

}

public class Bike extends Vehicle {

    int speed = 100;

    void display() {

        System.out.println(speed); 

    }

    public static void main(String args[]) {

        Bike b = new Bike();

        b.display();

    }

}

100

50

Lỗi biên dịch

Không có kết luận đúng

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Kết quả của chương trình in ra là gì?

class Vehicle {

    int speed = 50;

}

public class Bike extends Vehicle {

    int speed = 100;

    void display() {

        System.out.println(super.speed); 

    }

    public static void main(String args[]) {

        Bike b = new Bike();

        b.display();

    }

}

100

50

Lỗi biên dịch

Không có kết luận đúng

Create a free account and access millions of resources

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?