Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Me With Basics

 
Aditya Desai
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Few basic doubts..!!

1. If we try to inherit a private class. Would the extend statement give error or the object creation statement will provide error?

2. Suppose we have a no-arg constructor and a parameterized constructor. Is it ok if we do not create a no-arg object. I mean is it ok if a constructor (which is a no arg constructor in this example) is never called in a class.

3.If class B extends class A and class C extends class B. Can we call the methods of class A with the methods class C.?

4.In what all conditions an object of one class can access another class?

5.Does the compiler will provide super() in every condition in the constructor if we haven't written it.? ( If yes then we dont have to look for compilation fails because of the missing super() in exams)?

6. Can a static method be overridden?

Two more questions
1.Does OCAJP 7 contains drag and drop questions?

2.I am a student and when I am trying to create an oracle account it is asking me to fill company name which is mandatory..!!! help


 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Desai wrote:1. If we try to inherit a private class. Would the extend statement give error or the object creation statement will provide error?

If you are referring to top-level classes, then you can only have classes with public or default access. Classes with protected or private access are not allowed. You can only use the protected and private access modifiers for inner classes (but this topic is not covered on the OCA exams)

Aditya Desai wrote:2. Suppose we have a no-arg constructor and a parameterized constructor. Is it ok if we do not create a no-arg object. I mean is it ok if a constructor (which is a no arg constructor in this example) is never called in a class.

That's ok! You can even have 10 constructors defined in a class and none of them are called. That makes this class with these constructors a little bit useless because no objects are constructed if constructors are not called, but it's not a problem, it's allowed.

Aditya Desai wrote:3.If class B extends class A and class C extends class B. Can we call the methods of class A with the methods class C.?

That depends on the visibility of the methods from A. If the methods are visible/accessible to class C then it's yes; otherwise it's no.

Aditya Desai wrote:4.In what all conditions an object of one class can access another class?

The visibility of that class and that depends on the access modifier. If it's public, any object will be able to access the other class; if it's default (no access modifier provided), only classes of the same package will be able to access the other class.

Aditya Desai wrote:5.Does the compiler will provide super() in every condition in the constructor if we haven't written it.? ( If yes then we dont have to look for compilation fails because of the missing super() in exams)?

If you don't provide a call to another constructor of the same class (using this) or a call to a constructor of the parent class (using super), then the compiler will provide a call to super() for you. And that's fine as long as in the parent class there's a no-arg constructor; if this constructor doesn't exist the code won't compile as illustrated here

Aditya Desai wrote:6. Can a static method be overridden?

No! A static method is not inherited and only inherited methods can be overridden. A static method can be hidden (if you declare exactly a method with the exact same signature in the child class).

Aditya Desai wrote:1.Does OCAJP 7 contains drag and drop questions?

No! No drag-and-drop questions anymore on the exams.

Aditya Desai wrote:2.I am a student and when I am trying to create an oracle account it is asking me to fill company name which is mandatory.

Maybe enter the name of your school or use "Student" or use "N/A" (which stands for "not applicable").

Hope it helps!
Kind regards,
Roel
 
Aditya Desai
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In 1st question I am asking if we INHERIT a private class. I am not talking about top level class.
In question 3 I mean can class A be considered as a parent class of class C?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Desai wrote:In 1st question I am asking if we INHERIT a private class. I am not talking about top level class.

And my point is: you can't create a private top-level class (only inner classes), so how will you inherit from a private class. To make it more obvious, this code does NOT compileIf MyPrivateClass does not compile, how will you be able to write code like this

Aditya Desai wrote:In question 3 I mean can class A be considered as a parent class of class C?

You can easily verify this for yourself using the instanceof operator.

Hope it helps!
Kind regards,
Roel
 
Aditya Desai
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Few more question.

If we re-throw an exception from catch block. Is it possible to catch that exception( I have read somewhere that it is not possible to catch an exception which has been rethrown because it is not thrown from a try block) ?

Can break; be used in if() condition?

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Desai wrote:Few more question.

You can find an answer to these questions very easily yourself by just creating a similar code snippet and try to compile (and run) it using javac and java. If it doesn't compile, it isn't allowed; if it does, it is allowed and you can do it.

And creating such code snippets can be very easy and be done very quickly as well. With this code snippet (only 4 lines of code) you'll get an answer on your 2nd question "Can break; be used in if() condition?" (if you compile the code)


Hope it helps!
Kind regards,
Roel
 
Aditya Desai
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll run the "If" concept that I asked but can you please ans the question about catch and exception i asked..!!

And

how to ans these type of questions?? what are the facts on the basis of I can ans these kind of questions


Which of these assignments are valid?

A. short s = 12 ;
B. long g = 012 ;
C. int i = (int) false;
D. float f = -123;
E. float d = 0 * 1.5;
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Desai wrote:I'll run the "If" concept that I asked but can you please ans the question about catch and exception i asked..!!

I answered it: create an appropriate code snippet and see what the compiler thinks about that code (just like with the if statement).

Aditya Desai wrote:how to ans these type of questions?? what are the facts on the basis of I can ans these kind of questions

To answer this type of questions, you'll need to know the ranges of the different primitive data types (which can be easily found using Google).
 
Aditya Desai
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any difference between int x and Integer x ..... Long x and long x?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Desai wrote:Is there any difference between int x and Integer x ..... Long x and long x?

Yes! int is a primitive data type, Integer is a primitive wrapper class (which thus extends Object). And the same applies to long and Long, short and Short, and so on.
 
Aditya Desai
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are questions on wrapper classes directly or indirectly included in exam..!!??

And THANKS A LOT..for answering all my questions..
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Desai wrote:Are questions on wrapper classes directly or indirectly included in exam..!!??

Some exam takers mentioned they got questions about wrapper classes on the exam (when used with e.g. ArrayList), others didn't. So to be confident, just have a look at the wrapper classes, it's really not that hard.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic