Lets see what Jesus says about this
MATTHEW 19 [16]And, behold, one came and said unto him, Good Master, what good thing shall I do, that I may have eternal life? [17] And he said unto him, Why callest thou me good? there is none good but one, that is, God: but if thou wilt enter into life, keep the commandments. [18] He saith unto him, Which? Jesus said, Thou shalt do no murder, Thou shalt not commit adultery, Thou shalt not steal, Thou shalt not bear false witness, [19] Honour thy father and thy mother: and, Thou shalt love thy neighbour as thyself.
The works these people will be judged by is that portion of the ten commandments that pertain to your interaction with man. Jesus tells us that, so you can take it to the bank. Good news for Fred. The man asked Jesus how he should attain eternal life. Jesus did not mention even one of the ten commandments that deal with your interaction with God. Had Jesus been asked, how shall I be saved to the kingdom? Jesus would have given a totally different answer.
Here, Jesus laid down the law as a schoolmaster to lead the rich young ruler to Christ.
He was not saying that the man could be justified by his works; otherwise He would be contradicting what we know to be true salvation doctrine in the New Testament.
The man was trusting in his works to save him, so, in the passage, Jesus lays down the law to show the man that he is incapable of entering in by what he could do.
In order for the man to be saved, he would in fact have to receive salvation as a gift, after Jesus died on the Cross to provide that gift.
Also, before Jesus died, there was no provision for that gift. So Jesus told the man what he needed to do to be saved apart from that gift being given; which showed the man that he was a sinner in need of a Saviour.
No one can keep the law (Galatians 3:22, Galatians 6:13, Romans 3:23); so the man, in being told to keep the law, is being told that he cannot enter in, as long as he is trusting in his works to save him.
Only in receiving the gift of salvation might the man actually become able to be obedient in the way that Jesus told him to become obedient. He would need the gift of the Holy Spirit in order to be able to measure up.
But even in this, the man would still need the shed blood of Jesus Christ as the provision by which he might be forgiven of all of his sins. Without this gift, the man might be able to turn over a new leaf but he would still not be saved; because all of his past sins would still have to be judged, having not been forgiven; and thus he would be condemned.