• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Abstract Class

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks

My question is following statement is true or not if true then why iam getting error in following code

" If any class extends to abstract class then it's sub-class must be declare as abstract if we are not inherting any method of that class abtract class to sub-class."

I am getting error "TestAbsClass2 is not abstract and does not override abstract method show() in TestAbs2_class

abstract class TestAbs2_class
{

public void show2()
{
System.out.println("Non-Abstract method1 Inherited");
}

abstract void show();
abstract void display();
}


class TestAbsClass2 extends TestAbs2_class
{


void display()
{
System.out.println("Abstract method1 Inherited");
}


public static void main(String args[])
{
TestAbsClass2 obj1=new TestAbsClass2();
//obj1.show();
//obj1.show2();

obj1.display();
}
}
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gaurav,

show() method is defined as abstract in TestAbs2_class but not implemented in the derived class TestAbsClass2. That is why you are getting this error.

TestAbsClass2 class either define all the abstract methods from the base class or should be marked as abstract.


The first concrete subclass of any abstract class must provide implementation for all abstract methods of its super class



Hope this will clear your doubt.
 
Gaurav Pavan Kumar Jain
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thank you very much it's clear my big doubt
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic