Correct the error in the following Java code snippet to properly encapsulate the 'name' field.
class Person {
public String name;
public String getName() {
return name;
}
public void setName(String newName) {
this.name = newName;
}
}
صحح الخطأ في الشفرة البرمجية جافا التالية لتغليف حقل 'name' بشكل صحيح.How do you increment a variable `x` by 1 in Java?
Anonymous Quiz
32%
x++
11%
x+=1
2%
x=x+1
54%
All of the above
What will be the output of the following Java code snippet that demonstrates the use of static variables?
ماذا سيكون المخرج للشفرة البرمجية جافا التالية التي توضح استخدام المتغيرات الثابتة؟
class Counter {
static int count = 0;
Counter() {
count++;
System.out.println(count);
}
}
public class TestCounter {
public static void main(String[] args) {
Counter c1 = new Counter();
Counter c2 = new Counter();
Counter c3 = new Counter();
}
}
ماذا سيكون المخرج للشفرة البرمجية جافا التالية التي توضح استخدام المتغيرات الثابتة؟
What is the default value of a boolean variable in Java?
Anonymous Quiz
17%
true
54%
false
23%
null
5%
0
What is the output of the following Java code snippet using polymorphism?
ما هو مخرج الشفرة البرمجية جافا التالية باستخدام الشكلية البوليمورفية؟
class Animal {
void sound() {
System.out.println("Animal makes a sound");
}
}
class Dog extends Animal {
void sound() {
System.out.println("Woof");
}
}
public class Test {
public static void main(String[] args) {
Animal myAnimal = new Dog();
myAnimal.sound();
}
}
ما هو مخرج الشفرة البرمجية جافا التالية باستخدام الشكلية البوليمورفية؟
What is the output of the following Java code?
```java
String str1 = "Java"; String str2 = new String("Java"); System.out.println(str1 == str2); ```
```java
String str1 = "Java"; String str2 = new String("Java"); System.out.println(str1 == str2); ```
Anonymous Quiz
35%
true
38%
false
16%
Java
12%
An exception is thrown
Identify and fix the error in the following Java code snippet that attempts to implement polymorphism.
حدد وأصلح الخطأ في الشفرة البرمجية جافا التالية التي تحاول تنفيذ الشكلية البوليمورفية.
interface Shape {
void draw();
}
class Circle implements Shape {
public void draw() {
System.out.println("Circle drawn");
}
}
public class TestPolymorphism {
public static void main(String[] args) {
Shape shape = new Circle();
shape.draw();
}
}
حدد وأصلح الخطأ في الشفرة البرمجية جافا التالية التي تحاول تنفيذ الشكلية البوليمورفية.
Which of the following is not a valid Java data type?
Anonymous Quiz
5%
int
4%
double
7%
String
5%
boolean
79%
real
👍1
Identify and fix the error in the following Java code snippet to correctly demonstrate the concept of an abstract class.
حدد وأصلح الخطأ في الشفرة البرمجية جافا التالية لتوضيح مفهوم الصف المجرد بشكل صحيح.
abstract class Animal {
abstract void eat();
}
class Dog extends Animal {
void eat() {
System.out.println("Dog eats food");
}
}
حدد وأصلح الخطأ في الشفرة البرمجية جافا التالية لتوضيح مفهوم الصف المجرد بشكل صحيح.
Which keyword is used to declare an array in Java?
Anonymous Quiz
7%
array
11%
Array
34%
[]
49%
There is no specific keyword; use the data type followed by []
Fix the error in the following Java code snippet to correctly compare two strings for equality.
أصلح الخطأ في الشفرة البرمجية جافا التالية لمقارنة سلسلتين نصيتين بشكل صحيح من أجل المساواة.
String str1 = "Java";
String str2 = "java";
System.out.println(str1 == str2);
أصلح الخطأ في الشفرة البرمجية جافا التالية لمقارنة سلسلتين نصيتين بشكل صحيح من أجل المساواة.
Which method must be implemented by a class that implements the `java.lang.Runnable` interface?
Anonymous Quiz
52%
run()
17%
start()
23%
execute()
8%
perform()
What will be the output of the following Java code snippet that demonstrates the use of the ternary operator?
ماذا سيكون المخرج للشفرة البرمجية جافا التالية التي توضح استخدام العامل الثلاثي؟
int a = 10, b = 5;
int result = (a > b) ? a : b;
System.out.println(result);
ماذا سيكون المخرج للشفرة البرمجية جافا التالية التي توضح استخدام العامل الثلاثي؟
Which principle of Object-Oriented Programming allows a subclass to provide a specific implementation of a method that is already provided by one of its superclasses?
Anonymous Quiz
16%
Encapsulation
27%
Polymorphism
49%
Inheritance
8%
Composition
Fix the error in the following Java code snippet to correctly compare two strings for equality.
أصلح الخطأ في الشفرة البرمجية جافا التالية لمقارنة سلسلتين نصيتين بشكل صحيح من أجل المساواة.
String str1 = "Java";
String str2 = "java";
System.out.println(str1 == str2);
أصلح الخطأ في الشفرة البرمجية جافا التالية لمقارنة سلسلتين نصيتين بشكل صحيح من أجل المساواة.
👍3
What is the output of the following code snippet?
int moon = 9, star = 2 + 2 * 3;
float sun = star>10 ? 1 : 3;
double jupiter = (sun + moon) - 1.0f;
int mars = --moon <= 8 ? 2 : 3;
System.out.println(sun+", "+jupiter+", "+mars);
Which collection interface represents a group of objects as a single unit in Java?
Anonymous Quiz
51%
List
8%
Set
11%
Map
31%
Collection
What is the output of the following Java program that demonstrates method overloading?
ما هو مخرج البرنامج جافا التالي الذي يوضح إعادة تحميل الطريقة؟
class DisplayOverloading {
public void disp(char c) {
System.out.println(c);
}
public void disp(char c, int num) {
System.out.println(c + " " + num);
}
}
public class Sample {
public static void main(String[] args) {
DisplayOverloading obj = new DisplayOverloading();
obj.disp('a');
obj.disp('a', 10);
}
}
ما هو مخرج البرنامج جافا التالي الذي يوضح إعادة تحميل الطريقة؟
❤2👍1
What does the `instanceof` keyword check?
Anonymous Quiz
55%
If a variable is an instance of a specific class
14%
If a class is a subclass of another
26%
If a method exists in a class
5%
If a variable is initialized