• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assert and private constructor

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a recent mock-exam that i attempted the following assertion was made:

String y = "test ";
String x;

assert(x > 1) : x = y + 1;

is this valid because x resolves to test 1 (i.e a value) ?

and will the following assertion be valid

String test = null;

assert (x > 1) : test;

Another question tested the functionality of a private constructor:

Given the following:

class Parent{

private Parent(){
//Code
}

}

class Child extends Parent{

Child(){
//Code
}
}


Now if I, in some other context, try to instantiate a Child:

Child myChild = new Child();

I should get an error since the call to super(); won't be allowed, right ?

A followup to this. Is the only way to circumvent the above problem to either make an overloaded (non-private) constructor in Parent and then call that explicitly from the Child() constructor, or to simply remove the private, or are there other ways around this ?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you go write some code
 
money grubbing section goes here:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic