Quiz 2-1
Quiz 2-1
1.
System.out.println("MMM");
}}
System.out.println("NNN"); 2
method
super.displayResult();
}}
%
2.
class Sample {
void print() {
System.out.println("Hello");
1
o 1 2
class Main {
apI samp
Sample[]&
arrObj = new Sample[3];
arrObj[0].print ();
-
arrObj[1].print();
&
arrObj[2].print();
&
Hello
3.
class Animal {
is Animal() {
-
-a)
&
System.out.println("I am an animal");
-
2
: a) % 10
class Dog extends Animal {
&
201
i
Dog() {
super();
System.out.println("I am a dog");
class Main {
Si
Dog dog1 = new Dog();
s }
s
}
4.
-t public class C {
private int x1=6;
· }
public int x3 =10;
E 3
public class A extends C {
i
A obj = new A();
-
System.out.println(obj.x2);
System.out.println(obj.x3);
}
7
The output:
10
je 5. binew
g
j
class OuterClass {
j int x = 10;
static
-
class InnerClass { or
O
}
S int y = 5;
⑧}
8,
8 OuterClass.InnerClass myInner = new OuterClass.InnerClass();
-
-
-
--
System.out.println(myInner.y);
} 5
4
The output:
Q2. Find and correct the errors in each of the following Java codes:
1.
)
class Car{
.
5
String make;
-[ String model;
Car(String ma, String mo){
O
this.make=ma;
this.model=mo;
g
}
String fuelType;
this.cc=cc;
this.fuelType=ft;
O
}
5
7
=
-5 3
&,
-
-
.
}} SS , 6)
·
car ·
Motor m = C .
new Motor
-S ,81
-
2. M
public class main {
E
final Double x = 2.0 ;
> Error
myObj.x = 7.0; -
-
System.out.println(myObj.x);
}}
final
final is
-51 *
XT1 *
j =50 61838 , -
*
-4) y
3.
public&
final class Vehicle {
System.out.println("Any Vehicle");
6
-d) i
}
delete final
Xsenno
public class Car extends Vehicle{
4.
String Name;
double price;
Name = name;
price = price;
storeName = "Al-Nahdi";
5. final jex
-
final class Programming{
String Name="SW";
Ennon
}
String feature="Inheritance";