0% found this document useful (0 votes)
34 views8 pages

Quiz 2-1

Quize
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views8 pages

Quiz 2-1

Quize
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Quiz 2

Q1. What is the output of the following snippets of codes?

1.

public class Aclass {

public void displayResult() {

System.out.println("MMM");

}}

public class Bclass extends Aclass {

public void displayResult() { :


Main
-

System.out.println("NNN"); 2
method
super.displayResult();

}}

The output: No output

%
2.

class Sample {

void print() {

System.out.println("Hello");

1
o 1 2

class Main {
apI samp

public static void main(String args[]) {

Sample[]&
arrObj = new Sample[3];

arrObj[0] = new Sample();

arrObj[1] = new Sample();

arrObj[2] = new Sample();

arrObj[0].print ();
-

arrObj[1].print();
&

arrObj[2].print();
&

The output: Hello


Hello

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 {

public static void main(String[] args) {

Si
Dog dog1 = new Dog();
s }
s
}

The output: Jam an Animal


Jam a
dog

4.

-t public class C {
private int x1=6;

protected int x2=7;

· }
public int x3 =10;

E 3
public class A extends C {

public static void main(String[] args){

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;

⑧}

public class Main {

public static void main(String[] args) {


8
35's
-

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
}

class Motor { &


int cc;

String fuelType;

Motor(int cc, String ft){

this.cc=cc;

this.fuelType=ft;

O
}

public class Test {

public static void main(String[] args) {


5
55,81 8211
.

5
7
=

-5 3
&,
-
-
.

Car c = new Car("Toyota", "Camry");

Motor m= Motor( 2500, "hydrogen"); >


- Ernon
-

}} SS , 6)
·
car ·
Motor m = C .
new Motor

-S ,81
-

2. M
public class main {

E
final Double x = 2.0 ;

public static void main(String[] args) {

Main myObj = new Main();

> 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 {

public void Drive(){

System.out.println("Any Vehicle");

6
-d) i
}
delete final
Xsenno
public class Car extends Vehicle{

public void Drive(){

System.out.println("It is a kind of Vehicle");

4.

public class DrugStore

String Name;

double price;

static String storeName;

public DrugStore(String name, double price)


--

Name = name;

price = price;

storeName = "Al-Nahdi";

public static void main(String[] args) 2119


{
X
"Danadal" ,
2 . 5) ;
DrugStore customer1 = new DrugStore("Panadol"); Error
&
-

System.out.println("The Store Name: " + DrugStore.storeName);


7
}

5. final jex
-
final class Programming{

String Name="SW";
Ennon
}

class OOP extends Programming {


&

String feature="Inheritance";

public class TestMain {

public static void main(String[] args) {

OOP progLang=new OOP ();

System.out.println("OOP Feature:"+ progLang. feature);

You might also like