Search Header Logo

Ôn tập kế thừa ép kiểu

Authored by Kiều Thị

Fun

1st - 5th Grade

Used 18+ times

Ôn tập kế thừa ép kiểu
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

7 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 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

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 System.out.println("Programmer salary is: " + p.salary); do Programmer không có salary

Programmer salary is: 1000.0

Bonus of Programmer is: 150

2.

MULTIPLE CHOICE QUESTION

1 min • 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 mã d.bark

3.

MULTIPLE CHOICE QUESTION

1 min • 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();

}

}

Kết quả của hàm main là

40

Hello Java

Lỗi biên dịch dòng System.out.println(obj.data);

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

Không có lỗi xảy ra

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

4.

MULTIPLE SELECT QUESTION

1 min • 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ả của hàm main 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

1 min • 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ả của hàm main 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

1 min • 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

1 min • 1 pt

class Bank {

int getRateOfInterest() {

return 0;

}

}

class SBI extends Bank {

int getRateOfInterest() {

return 8;

}

}

class ICICI extends Bank {

int getRateOfInterest() {

return 7;

}

}

class AXIS extends Bank {

int getRateOfInterest() {

return 9;

}

}

public class Test2 {

public static void main(String args[]) {

Bank b;

b = new SBI();

System.out.println("SBI Rate of Interest: " + b.getRateOfInterest());

b = new ICICI();

System.out.println("ICICI Rate of Interest: " + b.getRateOfInterest());

b = new AXIS();

System.out.println("AXIS Rate of Interest: " + b.getRateOfInterest());

}

}

SBI Rate of Interest: 8

ICICI Rate of Interest: 8

AXIS Rate of Interest: 9

SBI Rate of Interest: 8

ICICI Rate of Interest: 9

AXIS Rate of Interest: 9

SBI Rate of Interest: 8

ICICI Rate of Interest: 7

AXIS Rate of Interest: 9

SBI Rate of Interest: 9

ICICI Rate of Interest: 7

AXIS Rate of Interest: 9

Access all questions and much more by creating a free account

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?