Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
26 views4 pages

OOP Homework3

Uploaded by

nora.agha2005
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)
26 views4 pages

OOP Homework3

Uploaded by

nora.agha2005
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/ 4

King Abdullah II School of Information Technology

Object Oriented Programming


Homework 3 Due Date: 19 /5 /2024
-------------------------------------------------------------------------------------------------------------------------------
Student Name:Nora Agha Student ID: 0233318 Section Number:_________ 2

Q1. Identify the error in the following Java code?

class X{
//Class X Members class z can't extend from 2 classes
} because java supports single
class Y{ inheritance only
//Class Y Members
}
class Z extends X, Y
{
//Class Z Members
}

Q2. Find the output of the following program?


class A{
int i = 10;
10
} 10
class B extends A{ 20
int i = 20;
}
public class MainClass{
public static void main(String[] args){
A a = new A();
B b = new B();
A aa = new B();
System.out.println(a.i);
System.out.println(aa.i);
System.out.println(b.i);
}}

1
Q3. Find the output of the following program?
class A{
public A(){
System.out.println("Class A Constructor"); class A constructor
class B constructor
} class C constructor

}
class B extends A{
public B(){
System.out.println("Class B Constructor");
}}
class C extends B{
public C(){
System.out.println("Class C Constructor");
}}
public class TestClass{
public static void main(String[] args){
C c = new C();
}}

2
Q4. Find the output of the following program?
class A {
int i=4;
} 32
4
class B extends A {
int j=3;
int i=2;
public void display() {
super.i = j + i;
System.out.println(j + " " + i);
} }
public class TestClass {
public static void main(String args[]) {
B obj = new B();
obj.display();
A a = new A();
System.out.println(a.i);
}}

3
Q5. Fill in the blanks with the suitable statements:
public class Member{
private String name, id;
private double amountDue;
//fill in the blanks to initialize all the field variables
public Member(String name, String id, double amountDue){
this.name=name;
________________________
________________________
this.id=id;

________________________
this.amountDue=amountDue;

}
public String getName(){return name;}
public String getId(){return id;}
public double getAmount(){return amountDue;}
public void display(){ System.out.println("In class Member"); }
public String toSrting(){
return String.format("name is: %s , id is : %s , amountDue is %d\n:",name,id,amountDue);
}}
public class Student extends Member{
private String course;
//fill in the blanks to initialize the field variable.
public Student(String n, String i, double m, String c){
super(n,i,m);
________________________
________________________
this.course=c;

}
public String getCourse(){return course;}
// Write the missing part needed to call the toString method declared in the superclass and to
return the value of the course field.
public String toString(){ return String.format(________________________);}
"course is:%\n",course

Good Luck! 

You might also like