Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How do you think this?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which declare an abstract method in an abstract java class?
A. public abstract method();
B. public abstract void method();
C. public void abstract method();
D. public abstract void method(){/};
ans:B
I dont know the reason why the D isn't correct(Is it because the "/"?).please give some comment concern this case;
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there!
D is not correct, because an abstract method cannot have an inplementation. That means that an abstract methods' declaration must end with ; .
public abstract void method() {/} is illegal because the {} part is an implementation (albeit rather useless).
The / is also incorrect, as a comment in Java is either // or /* */.
Hope this helps!
/Kaspar
____________________________________________________________
which declare an abstract method in an abstract java class?
A. public abstract method();
B. public abstract void method();
C. public void abstract method();
D. public abstract void method(){/};
ans:B
I dont know the reason why the D isn't correct(Is it because the "/"?).please give some comment concern this case;
 
james gong
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you mean that a abstract method always have no method body?
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. A method that is declared abstract cannot have a method body. The only way an abstract method can make itself useful is when you extend the abstract class the method is a member of and override the method in this subclass:
public abstract class A {
public abstract void method();
}
public class B extends A {
public void method() {
System.out.println("Bump!");
}
}
If you extend an abstract class you have to override and implement its abstract methods (OR you have to declare the subclass abstract as well).
Hope this helps!
/Kaspar
 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to RHE, the order of the modifiers are not important. For instance, public static void main(String[] args) is just like static public void main(String[] args). So, why is
C. public void abstract method() not correct?
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cameron!
void is not a modifier, it is a return type. A return type must always immediately precede the method name.
/Kaspar
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Camaron,
As Kasper has correctly pointed out, the return type should
always preceed the method name. All the other modifiers can
have any order. But, you cannot have more that one modifiers
like public , protected, private.
e.g. You CANNOT declare a methdod like the following
<code>public protected void doubleModifierMethod() </code>.
Hope this clears the issue. Please reveert in case more
clarification is sought on this.
Ravindra Mohan.
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic