
Ôn tập kế thừa ép kiểu
Authored by Kiều Thị
Fun
1st - 5th Grade
Used 18+ times

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

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
10 questions
KATOTOHANAN O OPINYON
Quiz
•
5th Grade
10 questions
Are you smarter than a 5th Grader ?
Quiz
•
KG - 12th Grade
10 questions
Friendship Quiz
Quiz
•
5th Grade
12 questions
~MELANIE MARTINEZ QUIZ~
Quiz
•
5th Grade
9 questions
15 mins test
Quiz
•
1st - 5th Grade
10 questions
Fun with Newton
Quiz
•
5th - 10th Grade
11 questions
How well do you know your friend?
Quiz
•
3rd - 7th Grade
12 questions
Name that pokemon
Quiz
•
KG - Professional Dev...
Popular Resources on Wayground
8 questions
Spartan Way - Classroom Responsible
Quiz
•
9th - 12th Grade
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
14 questions
Boundaries & Healthy Relationships
Lesson
•
6th - 8th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
3 questions
Integrity and Your Health
Lesson
•
6th - 8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
9 questions
FOREST Perception
Lesson
•
KG
20 questions
Main Idea and Details
Quiz
•
5th Grade
Discover more resources for Fun
20 questions
Knowledge 8: Our Planet: The History of the Earth
Quiz
•
1st Grade
10 questions
Dr. Seuss
Quiz
•
KG - 5th Grade
20 questions
Fun Fun Friday!
Quiz
•
3rd - 5th Grade
30 questions
Grandparent's Day
Quiz
•
4th Grade
15 questions
Dr. Seuss Characters
Quiz
•
1st Grade
59 questions
Logos (Hard)
Quiz
•
KG - 5th Grade
19 questions
Grandparent's Day
Quiz
•
4th Grade
10 questions
Disney Characters
Quiz
•
2nd Grade