Actually he was asked at least three times. His answers are very instructive.
In Mathew 19:16 He was asked how to have eternal life by a rich man, and Jesus responded "Keep the commandments". The man asked which. Jesus rattled off about 5. The man said "I've kept all of these from my youth." (Understand, this was a really GOOD guy by earthly standards). But then Jesus responds, "If you would be perfect, go and sell that thou hast...". What Jesus did was he led the man up to a point that Jesus could show the man his sin. His sin was that he held riches in greater esteem than God.
Now look at the reaction from His disciples that follows..."Who then can be saved?" ... They were astounded, if this man who had kept so many of the commandments couldn't be saved, who could? Jesus said, "With man it's impossible, with God it's possible." Man cannot save himself, but God can save man.
Mathew 19:21 (also in Mark 10) Jesus said unto him, If thou wilt be perfect, go and sell that thou hast, and give to the poor, and thou shalt have treasure in heaven: and come and follow me. 22 But when the young man heard that saying, he went away sorrowful: for he had great possessions. 23 Then said Jesus unto his disciples, Verily I say unto you, That a rich man shall hardly enter into the kingdom of heaven. 24 And again I say unto you, It is easier for a camel to go through the eye of a needle, than for a rich man to enter into the kingdom of God. 25 When his disciples heard it, they were exceedingly amazed, saying, Who then can be saved? 26 But Jesus beheld them, and said unto them, With men this is impossible; but with God all things are possible.
In Luke 10:25, Jesus was asked by a Lawyer how to have eternal life. Jesus asked him what is written in the law?
Luke 10:27 Thou shalt love the Lord thy God with all thy heart, and with all thy soul, and with all thy strength, and with all thy mind; and thy neighbour as thyself. 28 And he said unto him, Thou hast answered right: this do, and thou shalt live.
The man eloquently summarizes the law and Jesus agrees. "Do this and you shall live." The problem is that none of us do this. What Jesus does with this question, is to say, "You know what is right, go and do it!" Again Jesus shows the man his sin. Watch what happens in the next verse.
Luke 10:29 But he, willing to justify himself, said unto Jesus, And who is my neighbour? Which sets Jesus up for the story of the good Samaritan, which afterwards he tells the man to go and do likewise.
The third time he is asked in John 3, it's by Nicodemus, a member of the Jewish Sanhedriin, the ruling council. And Jesus says, "Except a man be born of water and of the Spirit, he cannot enter into the kingdom of God. " Nicodemus responds with "What?!? How can you be born again?" Jesus response, "You are a master of Israel and you don't understand this?" Nicodemus should have understood it. There was enough in the Old Testament, that Nicodemus should have realized what Jesus was saying.
Nevertheless, Jesus goes on and explains it fully with the following:
John 3:14 And as Moses lifted up the serpent in the wilderness, even so must the Son of man be lifted up: 15 That whosoever believeth in him should not perish, but have eternal life. 16 For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. 17 For God sent not his Son into the world to condemn the world; but that the world through him might be saved. 18 He that believeth on him is not condemned: but he that believeth not is condemned already, because he hath not believed in the name of the only begotten Son of God. 19 And this is the condemnation, that light is come into the world, and men loved darkness rather than light, because their deeds were evil. 20 For every one that doeth evil hateth the light, neither cometh to the light, lest his deeds should be reproved. 21 But he that doeth truth cometh to the light, that his deeds may be made manifest, that they are wrought in God.
So understand, what the Lord requires of us is really pretty simple: Love God, love others. The law was given to help us understand better what it is to love God and to love our fellow man. Micah 6:8 - He hath shewed thee, O man, what is good; and what doth the LORD require of thee, but to do justly, and to love mercy, and to walk humbly with thy God? Romans 13:8 - Owe no man any thing, but to love one another: for he that loveth another hath fulfilled the law.
But the problem is that none of us do it. Thus we all have a sin problem that needs to be dealt with. That's why scripture says repeated that there are none that are righteous except for Jesus.
But then Scripture goes on to talk about the righteous. But what it says is that "God is our righteousness", "The Lord has become our salvation", "You alone are my salvation", "Abraham beleived God and it was counted unto him for righteousness". We have the imputed righteousness of Jesus.
Romans 4:2 For if Abraham were justified by works, he hath whereof to glory; but not before God. 3 For what saith the scripture? Abraham believed God, and it was counted unto him for righteousness. 4 Now to him that worketh is the reward not reckoned of grace, but of debt. 5 But to him that worketh not, but believeth on him that justifieth the ungodly, his faith is counted for righteousness. 6 Even as David also describeth the blessedness of the man, unto whom God imputeth righteousness without works, 7 Saying, Blessed are they whose iniquities are forgiven, and whose sins are covered. 8 Blessed is the man to whom the Lord will not impute sin.
In other words, keeping the law is good. It is what God requires. But what happens when we fail?
That grace, that undeserved unmerited grace, that awesome grace is what frees us. The Christian who understands this no longer fears sin. I can't screw up bad enough that Jesus will reject me. My ticket is punched. My salvation is assured. As Paul said, "Nothing in life nor death... can separate me from the love of God."
I don't want to sin because I love God, because He loves me. I want to obey Him. But if I fail, Jesus already paid for it, some 2000 years ago and sin will not be imputed unto me. That's freedom!!!!