Object Oriented Programming - Part 3

oop
Hello Readers, 
Continuing with OOPs, today I'll discuss some important concepts which can be asked as objective questions directly in Specialist Officer's exam. Please post your queries/doubts in comments section!

Read Part 1 and Part 2

'this' keyword

'this' keyword acts as a reference to current object. You can refer to any member of current object by using 'this'. From within a constructor, you can also use it to call another constructor in the same class (explicit invocation, that is called). 

'super' keyword

'super' keyword is used to refer to immediate parent class object. Inside a sub class method, you use it to refer to parent class's method. You can also invoke constructor of parent class. 

Object cloning

It is used to create exact copy of an object by using clone( ) method in object class. In addition to that, java.lang.Clonable Interface must be implemented by the class whose object we want to clone. 

'final' variable, method & class

  • final variable - If a variable is final, it will have constant values i.e you can not change it further. 
  • final method - it can't be overridden by sub class i.e sub class will be prevented from redefining it to prevent undesirable results. It can be inherited though. 
  • final class - it can't be extended or inherited further. It may provide security and efficiency. 

Memory areas allocated by JVM (Java Virtual Machine)

  • Method area
  • Heap
  • Stack
  • PCR (program counter register)
  • Native method stack

Wrapper classes

All the primitive data types in java are wrapped around by classes known as wrapper classes. When we convert primitive data type into object, it is called boxing and the opposite is called unboxing. 

Type Casting

It is used to convert data from one data type to another data type. Only type of data can be modified, not the actual data. This is of 2 types:
  • Widening cast - When you are assigning a smaller type value to a larger type i.e you try to widen the data. 
  • Narrowing cast - When you are assigning a larger type value to a smaller type i.e you try to narrow down the data.

SizeOf & TypeDef in C++

  • SizeOf operator - gives information about the amount of memory allocated to data types (user defined data types as well) and objects.
  • TypeDef operator - It is used to assign alternative names to existing data types. Used mostly with user defined data types.  

Garbage collection in Java

This is done automatically by JVM. It can not be forced explicitly. JVM can be requested by calling system.gc( ) method though. When an object doesn't have any reference, it is assumed that it is no longer required & memory occupied by that object is released. Sometimes, an object may need to close the connection or release the resources held before it is destroyed which is done by calling finalize ( ) method.

Download SO IT Notes here

Practice MCQs

1. Which of the following concepts mean adding new components to the program as it runs?

a) Data hiding
b) Data Binding
c) Dynamic loading
d) Dynamic binding

2. Which of the following concept means waiting until runtime to determine which function to call?

a) Dynamic Loading
b) Data Binding
c) Dynamic Binding
d) Data loading

3. Which one of the following options is correct about friend function?

a) It can access public data members of the class
b) It can access protected data members of the class
c) It can access private data members of the class
d) All are correct. 

Join 40,000+ readers and get free notes in your email

0 comments:

Post a Comment

Thanks for commenting. It's very difficult to answer every query here, it's better to post your query on IBPSToday.com