Adding functionality

  • Eclipse: Oxygen
  • Java: 1.8

This tutorial deals with describing various functionalities of Composition. As described earlier in composition we can ‘inherit’ objects which are used to reference the method or the attribute related to the class.

The same concept is described here when the attributes of processor class are accessed by the Demo class via Laptop.

Hello.Java

Output

Laptop [screen=17.0, processor=Processor [brand=intel, series=7200U, generation=7, cores=4, threads=4, cacheMemory=6MB, frequency=2.5Ghz, minFrequency=2.5Ghz, maxfrequency=3.1Ghz], ram=DDR4, hardDrive=2TB, graphicsCard=GraphicsCard [brand=Nvidia, series=1050, memory=4GB], opticalDrive=null, keyboard=backlit]
Gaming mode on
Current frequency: 3.1Ghz

Laptop.Java

Output

Laptop [screen=17.0, processor=Processor [brand=intel, series=7200U, generation=7, cores=4, threads=4, cacheMemory=6MB, frequency=2.5Ghz, minFrequency=2.5Ghz, maxfrequency=3.1Ghz], ram=DDR4, hardDrive=2TB, graphicsCard=GraphicsCard [brand=Nvidia, series=1050, memory=4GB], opticalDrive=null, keyboard=backlit]
Gaming mode on
Current frequency: 3.1Ghz

GraphicsCard.Java

Output

Laptop [screen=17.0, processor=Processor [brand=intel, series=7200U, generation=7, cores=4, threads=4, cacheMemory=6MB, frequency=2.5Ghz, minFrequency=2.5Ghz, maxfrequency=3.1Ghz], ram=DDR4, hardDrive=2TB, graphicsCard=GraphicsCard [brand=Nvidia, series=1050, memory=4GB], opticalDrive=null, keyboard=backlit]
Gaming mode on
Current frequency: 3.1Ghz

Contributed by: Poonam Tomar


VIEW COURSES

Buy me a coffee!

 

PayTM QR (INDIA)

  • Get video tutorials
  • Project files set
  • Get┬áCertified

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu