Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

mock question

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.IOException;


public class Number1
{
public Number1() throws IOException
{
throw new IOException();
}
}

public abstract class Number2 extends Number1
{
public abstract void method();
}

An attempt to compile the above class definition ...

1 will cause a compiler error - non-abstract classes cannot be extended to abstract classes.
2 will cause a compiler error - a constructor must be provided which may or may not throw an IOException
3 will cause a compiler error - a constructor must be provided which must throw an IOException or one of its super types.
4 will not cause any compiler error. The class definition is perfectly legal
Ans is 3
Can anyone explain the answer
thanks in advance
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy ranchers,

class Number2 has an invisible default constructor that will call
super();

And because the constructor of the super class (Number1) is declared to throw an IOException, the subclass has to declare that it throws this (or a "higher") exception.


And:

"Viral Gala" !

Thanks for one of your first contribution to this forum and...

Welcome to the Ranch!




Hope you'll enjoy.




Only one small issue: The Java Ranch follows a certain policy regarding user names.
The main reasons why and a link how to change yours you'll find here:
http://www.javaranch.com/name.jsp


So, could you please change your user name before your next posting?
It will not affect anything you've already posted here. Just your user name will update.


I'm posting this because I am one of the moderators of this forum.


Yours,
Bu.
 
"To do good, you actually have to do something." -- Yvon Chouinard
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic