Does apex support abstraction?

Yes, apex is an object-oriented language, so it supports all the features of OOPs. You can create a utility class and create some fundamental operations so that they are readily available for developers to be used. Developers may just use the method without knowing the actual code behind that. This is abstraction.

What is method overriding in apex?

Two methods with same names and same parameters but one in parent and another in a child class is known as overriding in apex. One of the examples is the methods in batch class. Start, execute and finish are required to be overridden by the class.

Describe a use case where a map can be used.

Consider a scenario where you want to store currency information of many countries in a way that each country represents its currency. This can’t be done by a list as it just stores data but can’t represent. Key of map can represent a country name and value as currency; this way all combinations can be stored with each other’s references. Map.put(‘USA’, “US dollar”); Map.put(‘India’, “INR”); Map...

Explain five methods of map class.

Put(key,value) is used to insert or update a value in map on the basis
of key.

Contains key(key) returns true if the key already exists in map else
returns false.

Remove(key) removes the key-value pair from the map.

Size() returns the number of elements in map.

Clear() to delete all elements from map at once.

What is a map? Write its syntax.

A map is a collection which stores values on the basis of key-value pair where the key is always unique, and value is stored on behalf of that key. Values nee not to be unique.

Map<id,account>mapOfAccounts = new Map<id,account>();

List_of_accounts[] = {acct0, acct1, acct2, acct3, acct4}; For(integer i=0; i< 5; i++){ If(I.isEvenNumber()){ List_of_accounts.remove(i); } } Using system debug new value of list is : acct1, acct2, acct4 and list out of bound error. The desired output after removing even numbers should be acct1, acct3. Can you explain the issue?

Let’s track it. Remove method accepts index to discard the value. For i=0, it is even number value at index 0 removed from list  updated list values: acct1, acct2, acct3, acct4. Please remember after removal operation; indexes are recalculated based on the new order of list. For i=1, it is not even number; Nothing happens. For i=2, it is even number; value at index 2 will be removed from list ...

Recent Posts

Recent Comments