Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

abstract method INFO Plz?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abstract class A
{
abstract short m1();
short m2() { return (short) 420; }
}

abstract class B extends A
{
// missing the code ??
short m1() { return (short) 42; }
}

which of the following statements are true?
A. Thc code will compile with no changes.

B. Class B must either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.

C.It is legal, but not required, for Class B to either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.


I didn�t understand the B and C options. A and C are the correct Answer. Why C is the correct answer?
Can any one tell about abstract class and method? If any abstract method extends another abstract class then what we have does in the base abstract method? Where I can get good java study material?
[ February 09, 2006: Message edited by: Kiran Chand Panga ]
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since class B is an abstrat class itself so it is not even necessary for it to implement any of the abstract methods of the super class.
Moreover since m2 is not an abstract method in class A, so any class which extends class A(whether it may be itself abstract or not) doesnt need to implement or declare this method.So option B is not right.

Answer C is perfectly all right because there will be no harm if you override the m2 method of class A in class B. Even if you declare the method m2() as abstract in class B then also it will work.(Remember class B is an abstract class & only abstract classes can have abtract methods).

Basically an abstract class is a sort of Contract between the implementing class and itself. It says that the implementing class will always implement the abstract methods of the abstract class.
If you take the example of "interfaces", it will be clear that interfaces are 100% abstract classes in other sense. All of the method declaration given inside the Interface will internally be treaten by the compiler like
"public abstract".

Hope that clarifies.
You can refer any Standard Java reference guide for these concepts.

Regards,
Ankit Pradhan
abstract class A
{
abstract short m1();
short m2() { return (short) 420; }
}

abstract class B extends A
{
// missing the code ??
short m1() { return (short) 42; }
}

which of the following statements are true?
A. Thc code will compile with no changes.

B. Class B must either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.

C.It is legal, but not required, for Class B to either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.


I didn�t understand the B and C options. A and C are the correct Answer. Why C is the correct answer?
Can any one tell about abstract class and method? If any abstract method extends another abstract class then what we have does in the base abstract method? Where I can get good java study material?
 
Crusading Chameleon likes the size of this ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic