Java Programming OOP Questions and Answers Set 1

Java Programming OOPs

Questions 1 to 10



1.
The default value of a static integer  variable of a class in Java is,
(a)  0                       (b)  1                       (c)  Garbage value   (d)  Null    (e)  -1.
2.
What will be printed as the output of the following program?
                  public class testincr
                  {
                  public static void main(String args[])
                  {
                     int i = 0;
                     i = i++ + i;
                     System.out.println("I = " +i);
                   }
                   }
(a)  I = 0           (b)  I = 1           (c)  I = 2                (d)  I = 3                (e)  Compile-time Error.
3.
Multiple inheritance means,
(a)   one class inheriting from more super classes
(b)   more classes inheriting from one super class
(c)   more classes inheriting from more super classes
(d)   None of the above
(e)   (a) and (b) above.
4.
Which statement is not true in java language?
(a)   A public member of a class can be accessed in all the packages.
(b)   A private member of a class cannot be accessed by the methods of the same class.
(c)   A private member of a class cannot be accessed from its derived class.
(d)   A protected member of a class can be accessed from its derived class.
(e)   None of the above.
5.
To prevent any method from overriding, we declare the method as,
(a)  static        (b)  const            (c)  final              (d)  abstract             (e)  none of the above.
6.
Which one of the following is not true?
(a)   A class containing abstract methods is called an abstract class.
(b)   Abstract methods should be implemented in the derived class.
(c)   An abstract class cannot have non-abstract methods.
(d)   A class must be qualified as ‘abstract’ class, if it contains one abstract method.
(e)   None of the above.
7.
The fields in an interface are implicitly specified as,
(a)  static only                                        (b)  protected                                        (c)  private
(d)  both static and final                         (e)  none of the above.
8.
What is the output of the following program:
                       public class testmeth
                       {
                           static int i = 1;
                           public static void main(String args[])
                            {
                                 System.out.println(i+” , “);
                                 m(i);
                                 System.out.println(i);
                            }
                            public void m(int i)
                            {
                               i += 2;                              
                            }
                       }
(a)  1 , 3                  (b)  3 , 1                  (c)  1 , 1                  (d)  1 , 0        (e)  none of the above.
9.
Which of the following is not true?
(a)   An interface can extend another interface.
(b)   A class which is implementing an interface must implement all the methods of the interface.
(c)   An interface can implement another interface.
(d)   An interface is a solution for multiple inheritance in java.
(e)   None of the above.
10.
Which of the following is true?
(a)   A finally block is executed before the catch block but after the try block.
(b)   A finally block is executed, only after the catch block is executed.
(c)   A finally block is executed whether an exception is thrown or not.
(d)   A finally block is executed, only if an exception occurs.
(e)   None of the above.

Answers


1.
Answer : (a)
Reason:  The default value of a static integer  variable of a class in Java is 0.
2.
Answer : (b)
Reason:  1
                The execution goes on like this:
                          int i = 0;    //  i becomes 0
                          i = 0 + i;  //    now, i becomes 1
                          i = 0 + 1;  //    perform addition and assign 1 to i.
3.
Answer : (a)
Reason:  Multiple inheritance means one class inheriting from more super classes.
4.
Answer : (b)
Reason:  Private members of a class can be accessed by the methods within the same class.
5.
Answer : (c)
Reason:  Final methods of the base class cannot be overridden in the derived Class.
6.
Answer : (c)
Reason:  An abstract class can contain both abstract and non-abstract methods.
7.
Answer : (d)
Reason:  The fields in an interface are implicitly specified as both static and final.
8.
Answer : (c)
Reason:  Parameter values are passed by value in the calling of a method, and  so a copy of the value is created in the method, and the original value is not affected by the method call.
9.
Answer : (c)
Reason:  An interface can extend another interface but not implement.
10.
Answer : (c)
Reason:  A finally block is executed whether an exception is thrown or not is correct.



 1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25  

 26   27   28   29   30  Next >>


28 comments :

  1. I get it very helpful.keep it up.Thanks

    ReplyDelete
    Replies
    1. Tks very much for your post.

      Avoid surprises — interviews need preparation. Some questions come up time and time again — usually about you, your experience and the job itself. We've gathered together the most common questions so you can get your preparation off to a flying start.

      You also find all interview questions at link at the end of this post.

      Source: Download Ebook: Ultimate Guide To Job Interview Questions Answers:

      Best rgs

      Delete
  2. Answer of q. no. 8 is e. run it and find why .

    ReplyDelete
    Replies
    1. deepak is right, compiler returns console error

      Delete
  3. Question No. 8, Answer is not correct, The correct answer is compile time error because, the method m() is non static and you are calling without creating the instance on the main method.

    ReplyDelete
  4. Very good questions . Here are some 30 Java OOP concept interview questions, I have found immensely useful. Thanks

    ReplyDelete
  5. Question No.8 is not correct please re-check it

    ReplyDelete
  6. check here also for java related queries and get wonderful tips. check below link
    Java Training in Chennai

    ReplyDelete
  7. Thanks for sharing this unique and informative content which provided me the required information.
    SCM training in chennai

    ReplyDelete
  8. Learn and practice GK,TET, Aptitude questions and answers with explanation for interview http://www.gkindiaonline.com/

    ReplyDelete
  9. Hi, I am David from www.javamockexams.com, really thank you for your very exhaustive post, I am going to share it on all my social media!

    At www.javamockexams.com we also help those interested in becoming Java8 certified and Java9 in the close future.

    We offer a WebSimulator that accurately reproduce the Oracle exam environment and our question bank contains 4 totally unique tests with over 300 unique questions.
    We offer money back guaranteed if you do not pass the Oracle exam.

    Thanks again for your post!

    Thanks
    David

    ReplyDelete
  10. This information is impressive; I am inspired by your post writing style & how continuously you describe this topic. Java Training in Chennai

    ReplyDelete
  11. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Java Training in Chennai

    ReplyDelete
  12. Thanks! I was looking for object oriented programming exam questions and answers and your post is so, so, so helpful! Also, I'm really happy that I got so many question right! Thanks for the hard work!

    ReplyDelete
  13. This is one of the great blog. very nice and creative information.iam really impressive your topic.Thanks for sharing.


    Core Java Online Training

    ReplyDelete
  14. Thanks for sharing..Hi admin.., Iam the big follower of your blog. I read all your blog for gathering lot of informations.keep sharing more blogs..,


    Android Training in Chennai

    ReplyDelete
  15. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  16. If you need your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (even if they're dating somebody else now) you need to watch this video
    right away...

    (VIDEO) Win your ex back with TEXT messages?

    ReplyDelete
  17. This information is impressive; I am inspired by your post writing style & how continuously you describe this topic. White Label Website Builder

    ReplyDelete
  18. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  19. Nice and good article.. it is very useful for me to learn and understand easily.. thanks for sharing your valuable information and time.. please keep updating.morephp jobs in hyderabad.
     

    ReplyDelete
  20. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete