• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Some Basic Questions

 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Q1) State true or false :
protected access is provided even to subclasses that reside in a different package from the class that owns this feature.

Q2) Which of the following are valid method declarations?
a] abstract native void method();
b] abstract void method(){}
c] public static final void method(){}
d] abstract public synchronized void method();
e] public void abstract method();
f] public abstract void method() throws ArithmeticException;

Q3)Which of the following are valid member variable declarations?
a] abstract int i;
b] final int i;
c] final volatile int i;
d] public transient final i
e] protected static final int i
Q4)Which of the following are true regarding interfaces?
a] All methods in an interface are public,abstract and static
b] All interface methods should have public accessibility when implemented in class
c] All variables in an interface are public,static and final
d] interfaces can have constructors
e] It is valid to declare the methods explicitly in an interface as static.

Q5)True or False
a] Default constructor is provided for all classes
b] Default constructor is provided for the class which does define any constructor.
Q6)What would be the possible output?
1.class SampleConstructor
2.{
3.public static void main(String args[])
4. {
5. Parent p=new Parent(10);
6. Child c=new Child();
7.}
8.}
9.class Parent
10.{
11. public Parent(int i)
12. {
13. System.out.println("Value of i is "+i);
14. }
15.}
16.class Child extends Parent
17.{
18. public Child()
19. {
20. System.out.println("Constructor's do not have return type");
21 }
22}
a] compiles and runs with output Constructor's do not have return type
b] compiler error in line 18 prevents compilation
c] compiler error in line 11
d] compiles and runs with output Value of i is10
I am really confused.

Thanks in advance.
Bye.

21. Which of the following are invalid about constructors
a] constructors do not have return type
b] you cannot have more than one constructor in a class
c] To call a constructor defined in the superclass, you have to place the call as the first statement in the
calling constructor






 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

it is always a good idea to limit the number of qstns in your
post to one (best) or at the most two....
also, pl. go the the FAQ, I am sure most of these are already
answered there and so no one is spending time responding to this
mail.
regds.

- satya
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit, you have done a few posts where you have 10 or more questions in the post. Trust me, people will answer you if you limit each post to one or at most two questions. People find it too confusing and too daunting of a task to answer 10 questions in one post.
Ask these questions again in separate messages and me and many others will clear your doubts.
Thanks,
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic