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

Little 4Qs

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1. A method cant be overRidden to be more Private ?
if so ,
class cls {
void aMethod (){}
}
class clsChld extends cls {
X void aMethod(){}
}
// the X can Olny be Private . Ture ?
Q2 .
byte b = 1 ;
switch( b)
// does switch take byte as Param ?
Q3.
Strings are immutable , then
why ->
String s1="Mr." ;
s1+=" X" ;
System.out.println (s1); // output is Mr.X
Q4.
if a thread class is thrd
then
thrd t1 = new thrd();
thrd t2 = new thrd();
t1.start() ;
t1.start() ;
// what will happen ? any thing special ?
Thanks
ML

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


Q1. A method cant be overRidden to be more Private ?
if so ,
class cls {
void aMethod (){}
}
class clsChld extends cls {
X void aMethod(){}
}
// the X can Olny be Private . Ture ?


Answer - Fasle, Methods can not be overridden to be more private.They can be more public!


Q2 .
byte b = 1 ;
switch( b)
// does switch take byte as Param ?


Answer - Yes.
The type of the expression in a switch statement must be char, byte, short, or int. It will be converted to an int before it is compared to the case constants.


Q3.
Strings are immutable , then
why ->
String s1="Mr." ;
s1+=" X" ;
System.out.println (s1); // output is Mr.X


Answer - Strings ARE immutable.Here, a new string is created in a pool.


Q4.
if a thread class is thrd
then
thrd t1 = new thrd();
thrd t2 = new thrd();
t1.start() ;
t1.start() ;
// what will happen ? any thing special ?
Thanks


Answer - Nothing special ! You are creating two threads here.
Thanx
 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good Explanation ,Swati!
A overridden meth can be made more public not private.
I would like to add on the switch part that the case is always checked with the switch part whether it is in range or not.If not ,the compiler issues a error.
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic