Header Ads Widget

Ticker

6/recent/ticker-posts

Practical 5 Java

PRACTICAL 5

5-(1)

Define two nested classes: Processor and RAM inside the outer class: CPU with following data members class CPU { double price; class Processor{  double cores; double catch() String manufacturer; double getCache() void displayProcesorDetail() } protected class RAM{  class double memory; String manufacturer; Double clockSpeed; double getClockSpeed() void displayRAMDetail() } }

1.      Write appropriate Constructor and create instance of Outer and inner class and call the methods in main function

2.      2. Write a program to demonstrate usage of static inner class, local inner class and anonymous inner class

package com.company;

class CPU {
    double price;
    class Processor{
        double cores;
        String manufacturer;

        double getCache(){
            return 4.3;
        }
    }

    protected class RAM{

       
        double memory;
        String manufacturer;

        double getClockSpeed(){
            return 5.5;
        }
    }
}
public class Main {

    public static void main(String[] args) {

        CPU cpu = new CPU();

        // create an object of inner class Processor using outer class
        CPU.Processor processor = new CPU().new Processor();

        // create an object of inner class RAM using outer class CPU
        CPU.RAM ram = new CPU().new RAM();
        System.out.println("Processor Cache = " + processor.getCache());
        System.out.println("Ram Clock speed = " + ram.getClockSpeed());
    }
}

Post a Comment

0 Comments