0% found this document useful (0 votes)
3 views26 pages

Java Week6

The document contains a series of coding assignments for a student named Arul Amudhan G from Rajalakshmi Engineering College, focusing on object-oriented programming concepts in Java. It includes problem statements related to subscription services, product pricing with discounts, and sales tax calculations, along with sample inputs and outputs. Each assignment is evaluated with a total mark of 10, and the student has achieved full marks on all attempts.
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)
3 views26 pages

Java Week6

The document contains a series of coding assignments for a student named Arul Amudhan G from Rajalakshmi Engineering College, focusing on object-oriented programming concepts in Java. It includes problem statements related to subscription services, product pricing with discounts, and sales tax calculations, along with sample inputs and outputs. Each assignment is evaluated with a total mark of 10, and the student has achieved full marks on all attempts.
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

17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
7

7
01

01

01

01
Elsa subscribes to a premium service with a base monthly cost, a service
01

01

01

01
10

10

10

tax and an extra feature cost. Assist her in writing an inheritance program 10
24

24

24

24
that takes input for these values and calculates the total monthly cost.

Refer to the below class diagram:

Input Format
The first line of input consists of a double value, representing the base monthly
cost.
7

The second line consists of a double value, representing the service tax.
01

01

01

1
10
01

01

01

0
10

10

10

10

The third line consists of a double value, representing the extra feature cost.
24

24

24

24
Output Format
17

7
01

01

01
10

01

01

01
The output prints "Rs. X" where X is a double value, rounded off to two decimal
0
10

10

10

10
places.
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 10.0
2.5
5.0
7

17

17
01

01
Output: Rs. 17.50
10

0
01

01

01
00
10

10

10
Answer
1
24

24

24

24
import [Link];
class Subscription{
double monthlyCost;
double serviceTax;
double extraFeatureCost;

public Subscription( double mCost, double sTax, double xCost){


[Link] = mCost;
[Link] = sTax;
7

7
01

01

01

01
[Link] = xCost;
01

01

01

01
10

10

10

10
}
24

24

24

24
}

class PremiumSubscription extends Subscription{


public PremiumSubscription(double monthlyCost, double serviceTax, double
extraFeatureCost){
super(monthlyCost, serviceTax, extraFeatureCost);
}

public double calculateMonthlyCost(){


return (monthlyCost + serviceTax + extraFeatureCost);
7

7
01

01

01

1
10

}
01

01

01

0
10

10

10

10

}
24

24

24

24
public class Main {
17

7
01

01

01
public static void main(String[] args) {
10

01

01

01
0

Scanner scanner = new Scanner([Link]);


10

10

10

10
24

24

24

24
double baseMonthlyCost = [Link]();
double serviceTax = [Link]();
double extraFeatureCost = [Link]();

PremiumSubscription premiumSubscription = new


PremiumSubscription(baseMonthlyCost, serviceTax, extraFeatureCost);

double totalMonthlyCost = [Link]();

[Link]("Rs. %.2f%n", totalMonthlyCost);


7

17

17
01

01
10

0
01

01

01
00

[Link]();
10

10

10
1

}
24

24

24

24
}

Status : Correct Marks : 10/10


7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
7

7
01

01

01

01
Alice is managing an online store and wants to implement a program using
01

01

01

01
10

10

10

inheritance to calculate the selling price of products after applying 10


24

24

24

24
discounts.

Guide her by following the instructions:


Create a base class called Product with a public double attribute
[Link] a subclass called DiscountedProduct, which extends Product
and includes a private double attribute discount rate. This subclass has a
method called calculateSellingPrice() to determine the final selling price
after applying the discount.
Formula: Discounted selling price = price * (1 - discount rate)
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10

Input Format
24

24

24

24
The first line of input consists of a double value p, the initial price of the product.
17

7
01

01

01
10

01

01

01
0

The second line consists of a double value d, the discount rate.


10

10

10

10
24

24

24

24
Output Format
The output prints "Rs. X", where X is a double value, representing the calculated
discounted selling price, rounded off to two decimal places.

If the discount rate is greater than 1, print "Not applicable".

Refer to the sample output for formatting specifications.


7

17

17
01

01
10

0
01

01

01
Sample Test Case
00
10

10

10
1
24

24

24

24
Input: 50.00
0.20
Output: Rs. 40.00
Answer
import [Link];
class Product{
public double price;
}
7

7
01

01

01

01
class DiscountedProduct extends Product{
01

01

01

01
private double discRate;
10

10

10

10
24

24

24

24

public DiscountedProduct(double p, double dr){


[Link] = p;
[Link] = dr;
}

public double calculateSellingPrice(){


return price * (1 - discRate);
}
}
7

7
01

01

01

1
10

class ProductPricing {
01

01

01

0
10

10

10

10

public static void main(String[] args) {


24

24

24

24
Scanner scanner = new Scanner([Link]);
17

7
01

01

01
10

01

01

01
0

double initialPrice = [Link]();


10

10

10

10
double discountRate = [Link]();
24

24

24

24
DiscountedProduct discountedProduct = new
DiscountedProduct(initialPrice, discountRate);
double sellingPrice = [Link]();

if (sellingPrice >= 0) {
[Link]("Rs. %.2f%n", sellingPrice);
} else {
[Link]("Not applicable");
}
[Link]();
7

17

17
01

01
}
10

0
01

01

01
00

}
10

10

10
1
24

24

24

24
Status : Correct Marks : 10/10
7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
7

7
01

01

01

01
Preethi is working on a project to automate sales tax calculations for items
01

01

01

01
10

10

10

in a store. She wants to create a program that takes the price of an item 10
24

24

24

24
and the sales tax rate as input and calculates the final price of the item
after applying the sales tax.

Write a program using the class SalesTaxCalculator, which contains an


overloaded method named calculateFinalPrice to handle both integer and
double inputs. The program should also include a Main class that takes
user input, calls the appropriate method from SalesTaxCalculator, and
prints the final price of the item.

Formula Used: Final price = price + ((price * sales tax rate) / 100)
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10

Input Format
24

24

24

24
The first line of input consists of an integer price (the price of the item for integer
17

7
01

01

01
inputs).
10

01

01

01
0
10

10

10

10
The second line of input consists of an integer taxRate (the sales tax rate for
24

24

24

24
integer inputs).

The third line of input consists of a double price (the price of the item for double
inputs).

The fourth line of input consists of a double taxRate (the sales tax rate for
double inputs).
Output Format
The first line of output prints an integer, representing the final price of the item
7

17

17
01

01
10

0
after applying the sales tax for integer inputs (a and b).
01

01

01
00
10

10

10
1
24

24

24

24
The second line prints a double value, representing the final price of the item
after applying the sales tax for double-value inputs (m and n), rounded to two
decimal places.

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 100
7

7
01

01

01

01
10
01

01

01

01
100.0
10

10

10

10
24

24

24

24
5.0
Output: 110
105.00
Answer
import [Link];
class SalesTaxCalculator{
public static int calculateFinalPrice(int price, int taxRate){
return price + ((price*taxRate)/100);
}
7

7
01

01

01

1
10
01

01

01

public static double calculateFinalPrice(double price, double taxRate){


10

10

10

10
24

24

24

24
return price + ((price*taxRate)/100);
17

7
01

01

01
}
10

01

01

01
0

}
10

10

10

10
24

24

24

24
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
int intPrice = [Link]();
int intTaxRate = [Link]();
double doublePrice = [Link]();
double doubleTaxRate = [Link]();

int finalPriceInt = [Link](intPrice,


intTaxRate);
7

17

17
double finalPriceDouble =
01

01
10

0
01

01

01
[Link](doublePrice, doubleTaxRate);
00
10

10

10
1
24

24

24

24
[Link](finalPriceInt);
[Link]("%.2f", finalPriceDouble);
}
}

Status : Correct Marks : 10/10


7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
7

7
01

01

01

01
[Link] wants to create a program to calculate the volume of a Cuboid
01

01

01

01
10

10

10

and a Cube using method overriding. 10


24

24

24

24

Implements a base class Cuboid with attributes for length, width, and
height. Include a method calculateVolume() that computes the volume of
the cuboid.

Extends the base class with a subclass Cube representing a cube, where
all sides are equal. Override the calculateVolume() method in the Cube
class to compute the volume of the cube.

The program should take user input for the dimensions of the cuboid and
7

7
01

01

01

1
10

the side length of the cube and display the calculated volumes with two
01

01

01

0
10

10

10

10

decimal places.
24

24

24

24
17

7
Input Format

01

01

01
10

01

01

01
0

The first line of input consists of 3 space-separated double values, representing


10

10

10

10
24

the cuboid length, width, and height, respectively.

24

24

24
The second line consists of a double value, representing the side length of the
cube.
Output Format
The first line of output prints the volume of the cuboid, rounded off to two
decimal places.

The second line prints the volume of the cube, rounded off to two decimal
places.
7

17

17
01

01
10

0
01

01

01
00
10

10

10
1
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 60.0 60.0 60.0
50.0
Output: Volume of Cuboid: 216000.00
Volume of Cube: 125000.00
Answer
7

7
01

01

01

01
import [Link];
01

01

01

01
10

10

10

class Cuboid{ 10
24

24

24

24
double length;
double breadth;
double height;

public Cuboid(double l, double b, double h){


[Link] = l;
[Link] = b;
[Link] = h;
}
7

7
01

01

01

1
10
01

01

01

public double calculateVolume(){


10

10

10

10
24

24

24

24
return length * breadth * height;
17

7
01

01

01
}
10

01

01

01
0

}
10

10

10

10
24

24

24

24
class Cube extends Cuboid{

public Cube(double side){


super(side, side, side);
}

@Override
public double calculateVolume() {
return length * length * length;
7

17

17
01

01
}
10

0
01

01

01
00

}
10

10

10
1
24

24

24

24
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

double cuboidLength = [Link]();


double cuboidWidth = [Link]();
double cuboidHeight = [Link]();

// Regular object instantiation for Cuboid


Cuboid cuboid = new Cuboid(cuboidLength, cuboidWidth, cuboidHeight);
7

7
[Link]("Volume of Cuboid: %.2f\n", [Link]());
01

01

01

01
01

01

01

01
10

10

10

double cubeSide = [Link]();


10
24

24

24

24

// Upcasting - Using superclass reference for subclass object (DMD)


Cuboid cube = new Cube(cubeSide); // Upcasting
[Link]("Volume of Cube: %.2f", [Link]()); // Calls
Cube's method dynamically

[Link]();
}
}
7

Status : Correct Marks : 10/10


01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem statement:
7

7
01

01

01

01
Tim was tasked with developing a grocery shopping app. You have a class
01

01

01

01
10

10

10

hierarchy that includes Item, Produce, and OrganicProduce. Your goal is to 10


24

24

24

24
calculate the total cost of a shopping list, which may contain a mix of
regular produce and organic produce items. Additionally, you need to apply
discounts to organic items. Apply a 10% discount on organic produce items

Class Hierarchy:
Item: Base class for all items.
Produce: Subclass of Item for regular produce items.
OrganicProduce: Subclass of Produce for organic produce items.
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17

7
Input Format

01

01

01
10

01

01

01
0

The first line of input consists of an integer, 'n'.


10

10

10

10
24

24

24

24
For each 'n' item, the user will provide:

- A string 'type' representing the item type ('Regular' or 'Organic').


- A string 'name' represents the item name.
- A double 'price' represents the item price.
Output Format
The output will display the total cost of the shopping list, including discounts on
organic items.
7

17

17
01

01
10

0
01

01

01
00
10

10

10
1
24

24

24

24
Refer to the sample output for format specifications.
Sample Test Case
Input: 1
Regular Banana 1.99
Output: 1.99
Answer
import [Link];
7

7
01

01

01

01
class Item{
01

01

01

01
protected String name;
10

10

10

protected double price; 10


24

24

24

24

public Item(String n, double p){


[Link] = n;
[Link] = p;
}

public double calculateCost(){


return [Link];
}
}
7

7
01

01

01

1
10
01

01

01

class Produce extends Item{


10

10

10

10
24

24

24

24
public Produce(String name, double price){
17

7
01

01

01
super(name, price);
10

01

01

01
0

}
10

10

10

10
24

24

24

24
@Override
public double calculateCost(){
return [Link];
}
}

class OrganicProduce extends Produce{


private static final double DISCOUNT_RATE = 0.10;
7

17

17
01

01
public OrganicProduce(String name, double price){
10

0
01

01

01
00

super(name, price);
10

10

10
1

}
24

24

24

24
@Override
public double calculateCost(){
double finalPrice = [Link] * (1 - DISCOUNT_RATE);
return finalPrice;
}
}
public class Main {
public static void main(String[] args) {
7

7
Scanner sc = new Scanner([Link]);
01

01

01

01
01

01

01

01
10

10

10

int n = [Link]();
10
24

24

24

24
[Link](); // Consume newline

double totalCost = 0.0;

for (int i = 0; i < n; i++) {


String type = [Link]();
String name = [Link]();
double price = [Link]();

if ([Link]("Regular")) {
7

Item item = new Produce(name, price);


01

01

01

1
10
01

01

01

totalCost += [Link]();
0
10

10

10

10

} else if ([Link]("Organic")) {
24

24

24

24
Item item = new OrganicProduce(name, price);
17

7
01

01

01
totalCost += [Link]();
10

01

01

01
0

}
10

10

10

10
}
24

24

24

24
[Link]("%.2f%n", totalCost);
}
}

Status : Correct Marks : 10/10


7

17

17
01

01
10

0
01

01

01
00
10

10

10
1
24

24

24

24
7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 3
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
REC_2028_OOPS using Java_Week 6_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 14

Section 1 : MCQ

1. What will be the output of the following Java program?


7

7
01

01

01

01
class Test {
01

01

01

01
10

10

10

void show(int a) { 10
24

24

24

24
[Link]("Integer method");
}
void show(String s) {
[Link]("String method");
}
public static void main(String[] args) {
Test obj = new Test();
[Link](null);
}
}
7

7
01

01

01

1
10
01

01

01

Answer
10

10

10

10
24

24

24

24
Compilation error due to ambiguous method call
17

7
01

01

01
10

01

01

01
Status : Wrong Marks : 0/1
0
10

10

10

10
24

24

24

24
2. What will be the output of the following Java program?

class A {
int value = 10;
void display() {
[Link]("A's display: " + value);
}
}
class B extends A {
7

17

17
01

01
10

0
int value = 20;
01

01

01
00
10

10

10
void display() {
1
24

24

24

24
[Link]("B's display: " + value);
}
}
class Test {
public static void main(String[] args) {
A obj = new B();
[Link]();
[Link]("Value: " + [Link]);
}
}
7

7
01

01

01

01
01

01

01

01
Answer
10

10

10

10
24

24

24

24
B's display: 20 Value: 10
Status : Correct Marks : 1/1

3. What will be the output of the following program?

class A {
int x = 10;
}
7

7
01

01

01

1
10

class B extends A {
01

01

01

int x = 20;
10

10

10

10
24

24

24

24
}
17

7
01

01

01
10

01

01

01
0

class C extends B {
10

10

10

10
24

24

24

24
int x = 30;

void display() {
[Link](x);
[Link](super.x);
}
}

class Test {
public static void main(String[] args) {
7

17

17
01

01
C obj = new C();
10

0
01

01

01
00

[Link]();
10

10

10
1
24

24

24

24
}
}
Answer
3020
Status : Correct Marks : 1/1

4. What will be the output of the following Java program?


7

7
01

01

01

01
class Vehicle {
01

01

01

01
void startEngine() {
10

10

10

10
24

24

24

24
[Link]("Vehicle engine started");
}
}

class Car extends Vehicle {


void startEngine() {
[Link]("Car engine started");
}
}
7

7
01

01

01

class Main {
10
01

01

01

public static void main(String[] args) {


10

10

10

10
24

24

24

24
Vehicle myVehicle = new Car();
17

7
01

01

01
[Link]();
10

01

01

01
0

}
10

10

10

10
24

24

24

24
}
Answer
Car engine started
Status : Correct Marks : 1/1

5. Which of the following is true about method overriding in Java?

Answer
7

17

17
01

01
10

0
01

01

01
The method must have the same name, same parameters, and must be in
00
10

10

10
different classes with an inheritance relationship
1
24

24

24

24
Status : Correct Marks : 1/1

6. What will be the output of the following Java program?

class Vehicle {
void start() {
[Link]("Vehicle starts");
}
7

7
}
01

01

01

01
01

01

01

01
class Car extends Vehicle {
10

10

10

10
24

24

24

24
void start() {
[Link]("Car starts");
}
}
class ElectricCar extends Car {
void start() {
[Link]("Electric Car starts silently");
}
}
7

class Test {
01

01

01

1
10

public static void main(String[] args) {


01

01

01

0
10

10

10

10
24

24

24

24
Vehicle v = new ElectricCar();
17

7
01

01

01
[Link]();
10

01

01

01
0

}
10

10

10

10
24

24

24

24
}
Answer
Electric Car starts silently
Status : Correct Marks : 1/1

7. What will be the output of the following Java program?

class Parent {
7

17

17
01

01
void show() {
10

0
01

01

01
00

[Link]("Parent class");
10

10

10
1
24

24

24

24
}
}
class Child extends Parent {
void show() {
[Link]("Child class");
}
}
class Test {
public static void main(String[] args) {
Parent obj = new Child();
7

7
01

01

01

01
[Link]();
01

01

01

01
}
10

10

10

10
24

24

24

24
}
Answer
Child class
Status : Correct Marks : 1/1

8. Which of the following is the correct way for class B to inherit from
class A?
7

7
01

01

01

Answer
10
01

01

01

0
10

10

10

10

class B extends A {}
24

24

24

24
Status : Correct Marks : 1/1
17

7
01

01

01
10

01

01

01
0
10

10

10

10
9. What will be the output of the following code?
24

24

24

24
class A {
int sum(int x) {
return x + 2;
}
}

class B extends A {
int sum(int x) {
7

17

17
01

01
return [Link](x) * 2;
10

0
01

01

01
}
00
10

10

10
1

}
24

24

24

24
class C extends B {
int sum(int x) {
return [Link](x) - 3;
}
}

class Test {
public static void main(String[] args) {
7

7
C obj = new C();
01

01

01

01
01

01

01

01
[Link]([Link](4));
10

10

10

} 10
24

24

24

24
}
Answer
9
Status : Correct Marks : 1/1

10. What will be the output of the following Java program?


7

class Test {
01

01

01

1
10
01

01

01

void display(int a, int b) {


0
10

10

10

10
24

24

24

24
[Link]("Method 1");
17

7
01

01

01
}
10

01

01

01
0

void display(double a, double b) {


10

10

10

10
24

24

24

24
[Link]("Method 2");
}
public static void main(String[] args) {
Test obj = new Test();
[Link](10, 10.0);
}
}
Answer
Method 2
7

17

17
01

01
10

0
Status : Correct Marks : 1/1
01

01

01
00
10

10

10
1
24

24

24

24
11. What will be the output of the following code?

class A {
void display() {
[Link]("Display A");
}
}

class B extends A {
7

7
01

01

01

01
void display() {
01

01

01

01
[Link]("Display B");
10

10

10

10
24

24

24

24
}
}

class C extends B {
void display() {
[Link]();
}
}

class Test {
7

7
01

01

01

public static void main(String[] args) {


10
01

01

01

C obj = new C();


10

10

10

10
24

24

24

24
[Link]();
17

7
01

01

01
}
10

01

01

01
0

}
10

10

10

10
24

24

24

24
Answer
Display B
Status : Correct Marks : 1/1

12. Select the correct keyword for implementing inheritance through the
class.

Answer
7

17

17
01

01
10

0
01

01

01
extends
00
10

10

10
1

Status : Correct Marks : 1/1


24

24

24

24
13. What will be the output of the following Java program?

class A {
void display() {
[Link]("Class A");
}
}
7

7
01

01

01

01
01

01

01

01
class B extends A {
10

10

10

void show() { 10
24

24

24

24
[Link]("Class B");
}
}

class C extends B {
void print() {
[Link]("Class C");
}
}
7

7
01

01

01

1
10
01

01

01

class Test {
0
10

10

10

10
24

24

24

24
public static void main(String[] args) {
17

7
01

01

01
C obj = new C();
10

01

01

01
0

[Link]();
10

10

10

10
24

24

24

24
[Link]();
[Link]();
}
}
Answer
Class AClass BClass C
Status : Correct Marks : 1/1
7

17

17
01

01
14. What will be the output of the following program?
10

0
01

01

01
00
10

10

10
1
24

24

24

24
class A {
public int i;
private int j;
}
class B extends A {
void display() {
super.j = super.i + 1;
[Link](super.i + " " + super.j);
}
}
7

7
01

01

01

01
class inheritance {
01

01

01

01
public static void main(String args[]) {
10

10

10

10
24

24

24

24
B obj = new B();
obj.i=1;
obj.j=2;
[Link]();
}
}
Answer
Compile Time Error
Status : Correct Marks : 1/1
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
15. What will be the output of the following program?
17

7
01

01

01
10

01

01

01
0

class Vehicle {
10

10

10

10
24

24

24

24
String type = "Vehicle";
}

class Car extends Vehicle {


String type = "Car";
}

class Test {
public static void main(String[] args) {
Car c = new Car();
7

17

17
01

01
[Link]([Link]);
10

0
01

01

01
00

}
10

10

10
1
24

24

24

24
}
Answer
Car
Status : Correct Marks : 1/1
7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24

You might also like