• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OCA Mock Exam, Question 45 (K&B7)

 
Venny Ra
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K & B OCA 7 mock exam:

Question 45: which are true:

A. Private methods cannot be overriden in a subclass.
B. All classes in java can extend at most one class
C. All interface in Java can extend at most one interface.
D. All interface in Java can extend more than 1 interface.
E. It is possible to override methods in a class without extending another class


In the answers it says: A, B and D are correct.

However, don't you think E should be the right answer as well because really any class inherits Object class by default which means we can override any methods of that class (for example equals method) without actually extending another class.
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venny Ra wrote:However, don't you think E should be the right answer as well because really any class inherits Object class by default which means we can override any methods of that class (for example equals method) without actually extending another class.

No! Because you are extending Object. So you are definitely extending from another class, namely class Object. Only you don't have to type it explicitly, it happens implicitly (if you don't extend from another class).

Only inherited methods can be overridden (if the method is not final). So if you don't extend from another class (either directly or indirectly), you can't override methods.

Hope it heps!
Kind regards,
Roel
 
Venny Ra
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Venny Ra wrote:However, don't you think E should be the right answer as well because really any class inherits Object class by default which means we can override any methods of that class (for example equals method) without actually extending another class.

No! Because you are extending Object. So you are definitely extending from another class, namely class Object. Only you don't have to type it explicitly, it happens implicitly (if you don't extend from another class).

Only inherited methods can be overridden (if the method is not final). So if you don't extend from another class (either directly or indirectly), you can't override methods.

Hope it heps!
Kind regards,
Roel


hmmm, ok. Yeah it makes sense, although as a reader, it sounded like explicitly extending another class. But I'll settle my mind with your explanation.. Thanks
 
Venny Ra
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Venny Ra wrote:However, don't you think E should be the right answer as well because really any class inherits Object class by default which means we can override any methods of that class (for example equals method) without actually extending another class.

No! Because you are extending Object. So you are definitely extending from another class, namely class Object. Only you don't have to type it explicitly, it happens implicitly (if you don't extend from another class).

Only inherited methods can be overridden (if the method is not final). So if you don't extend from another class (either directly or indirectly), you can't override methods.

Hope it heps!
Kind regards,
Roel


1 more thing, the questions that has multiple choices. Is it marked wrong if I don't answer all options correctly. I mean no credit for partially right answer ?
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venny Ra wrote:Is it marked wrong if I don't answer all options correctly. I mean no credit for partially right answer ?

You'll get 1 point if you have selected all correct answers; you'll get 0 points in all other situations. So no points for a partially correct answer, which make sense as each question tells you how many correct answers to select. So that's already a big help to answer a question correctly.
 
Venny Ra
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Venny Ra wrote:Is it marked wrong if I don't answer all options correctly. I mean no credit for partially right answer ?

You'll get 1 point if you have selected all correct answers; you'll get 0 points in all other situations. So no points for a partially correct answer, which make sense as each question tells you how many correct answers to select. So that's already a big help to answer a question correctly.


Got it.. thank you again
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venny Ra wrote:hmmm, ok. Yeah it makes sense, although as a reader, it sounded like explicitly extending another class. But I'll settle my mind with your explanation.

When answering a mock exam (or the actual exam), you should not assume things which are not mentioned in the question and/or the answer options.

So if the question wants to test if you know that you don't need to type extends Object to extend from the Object class, the answer option could be: If you want to extend from class Object, you have to explicitly add extends Object to the class declaration.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic