Solomon was the child of David's old age, the last-born of all his sons. He was placed under the care of Nathan from his earliest years. At first, there was apparently no distinct purpose to make Solomon the king's heir. Absalom was still the king's favorite son and was looked on by the people as the destined successor. However, the death of Absalom when Solomon was about ten years old left the palace vacant, and David pledged his word in secret to Bath-sheba that Solomon, and no other, should be the heir.
David's words, doubtless, expressed his desire that his son's life should not be as his own had been, one of hardships and wars, dark crimes and passionate repentance, but instead be pure, blameless, peaceful, fulfilling the ideal of glory and of righteousness after which he himself had strived in vain. Apparently, David's influence over Solomon's character was exclusively for good. At the age of ten or eleven, he must have passed through the revolt of Absalom, and shared his father's exile. He would have been taught all that priests or Levites or prophets had to teach.
When David was old and feeble, Adonijah, Solomon's older brother attempted to gain possession of the throne, but he was defeated, and Solomon went down to Gihon and was proclaimed and anointed King Solomon. A few months later, after his father's death, Solomon found himself the sole occupant of the throne.