KEMBAR78
Find The Expected Output From These Code Segments:: BITP 3113 Exercise | PDF | Constructor (Object Oriented Programming) | Programming
0% found this document useful (0 votes)
187 views5 pages

Find The Expected Output From These Code Segments:: BITP 3113 Exercise

The document contains code snippets from multiple classes demonstrating inheritance, overriding methods, and calling overridden methods through super and subclasses. It also contains true/false questions about Java classes and OOP concepts.

Uploaded by

Nur Ain Atirah
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)
187 views5 pages

Find The Expected Output From These Code Segments:: BITP 3113 Exercise

The document contains code snippets from multiple classes demonstrating inheritance, overriding methods, and calling overridden methods through super and subclasses. It also contains true/false questions about Java classes and OOP concepts.

Uploaded by

Nur Ain Atirah
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/ 5

BITP 3113 Exercise

Find the expected output from these code segments:

1/5
BITP 3113 Exercise

class Base {
public static void show() {
System.out.println("Base::show() called");
}
}

class Derived extends Base {


public static void show() {
System.out.println("Derived::show() called");
}
}

class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}

2/5
BITP 3113 Exercise

class Grandparent {
public void Print() {
System.out.println("Grandparent's Print()");
}
}

class Parent extends Grandparent {


public void Print() {
System.out.println("Parent's Print()");
}
}

class Child extends Parent {


public void Print() {
super.super.Print();
System.out.println("Child's Print()");
}
}

public class Main {


public static void main(String[] args) {
Child c = new Child();
c.Print();
}
}

class Base {
public void foo() { System.out.println("Base"); }
}

class Derived extends Base {


private void foo() { System.out.println("Derived"); }
}

public class Main {


public static void main(String args[]) {
Base b = new Derived();
b.foo();
}
}

3/5
BITP 3113 Exercise

class Base {
public void show() {
System.out.println("Base::show() called");
}
}

class Derived extends Base {


public void show() {
System.out.println("Derived::show() called");
}
}

public class Main {


public static void main(String[] args) {
Base b = new Derived();
b.show();
}
}

class Base {
final public void show() {
System.out.println("Base::show() called");
}
}

class Derived extends Base {


public void show() {
System.out.println("Derived::show() called");
}
}

class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}

4/5
BITP 3113 Exercise

(this is a modified UML class diagram from our Lab 2 session)

Shirt
- shirtCode : String
- description : String
- size : char S=small M=medium L=large
- color : char B=blue R=red G=green Y=yellow
- unitPrice : double
- quantityInStock : int
- replenishStock : boolean
+ Shirt(shirtCode:String, quantityInStock:int, unitPrice:double)
+ calculateTotalStockValue():double
+ displayDetails():void

1. Create the following two Shirt objects:


“Kenzo”,100,55.00
“Paco Rabane”,80,70.00
2. Add size and color to both objects (use setter methods)
3. Calculate the current total stock value for both T shirts.
4. Modify the quantity in stock for Kenzo T-shirt to become 25.
5. Calculate the current total stock value for both T shirts.

Indicate TRUE or FALSE


1 Instance variable names may only contain letters and digits.
2 A class always has a constructor.
3 int is the name of a class available in the package java.lang.
4 Java bytecode is executed directly by the hardware.
5 A default constructor sets all Boolean fields to false.
6 A class can belong to more than one package.
7 A class cannot be extended from more than a single super class.
8 A class may not have more than three constructors.
9 The return type of a constructor is void.
10 The initialization, condition and increment part of a for loop are optional.

5/5

You might also like