• 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

Doubts on..Valiverus MockTest!!

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends ..
Today I did Valiveru's mock test and have some doubts.Have anyone done that test?
In one question it states:
class BaseClass{
statis void sayHello(){
System.out.println("Hi pal!!!I am BaseClass" }}
public static SubClass extends BaseClass{
static void sayHello(){
System.out.println("Am In SubClass");}
public static void main(String args[])
{BaseClass bc=new SubClass();
bc.sayHello;}}
The answer says it will print "Hi Pal!!!I am in BaseClass".Is it correct? I thought sayHello() is being overridden while it is a static class.
Please help.
Again
The statement : Static variables can be applied to instance variables,methods,code fragments and classes is TRUE or False.
Again one question goes like this:
If you want to create java GUI application using AWT,you constructed a frame calling
Frame f=new Frame();
What methods you need to call on the frame to make it visible?
A. f.setVisible(true;
B. f.setsize(true);
C. Both A & B
It says Answer C.But is B correct???
Anotherdoubt: Is there any method called Interrupted() in Thread Class??
Anotherdoubt: Is ths TRUE or FALSE :
Overridden methods return different return types and will be in different classes.
Please help friends.
Love Sarbani.
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static methods are not overridden, they are hidden. If you say something like
base a = new sub();
a.method()
where method is a static method, then since the class referenced is base, bases method gets invoked.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi first of all ur posting has lot of compile time errors please try by urself to compile and then post it , that would help and improve the discussion forum for sure
here is the corrected code

class BaseClass{
static void sayHello(){
System.out.println("Hi pal!!!I am BaseClass");
}
}
public static class SubClass extends BaseClass{
static void sayHello(){
System.out.println("Am In SubClass");
}
public static void main(String args[])
{BaseClass bc=new SubClass();
bc.sayHello();
}
}

First of all SubClass wont compile as top level class cannot be Static
lets assume that SubClass is not declared static then sayHello() in BaseClass is hidden by the sayHello() in SubClass .hence bc.sayHello() will print Hi pal!!!I am BaseClass
sure this helps u
 
Sarbani Mookherji
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sunita and Saharana,
Its clear.I got just confused.Actually staic methods can't be overridden to be non-static.I should have thought of it.
The code must have had compiler errors,I am very sorry.Will be more careful next time.
Thankx to both of u.
Love .....Sarbani.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic