rajesh baba

Greenhorn
+ Follow
since May 19, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by rajesh baba

import java.util.*;
class animal
{
animal()
{
System.out.println("i am called");
}
}
class alist
{
public static void main(String[] args)
{
ArrayList a1=new ArrayList();
System.out.println("intial size of array"+a1.size());
a1.add("1");
a1.add("2");
a1.add(new String("String"));
for(int i=0;i<9;i++)
a1.add(new animal());
animal a=(animal)a1.get(3);
System.out.println(a1);
Object[] list=a1.toArray();
Object sum=0;
for(Object k:list)
System.out.println("object is"+k);
}
}
output:
C:\jdk1.5.0_11\bin\coll>javac alist.java
Note: alist.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

what the note mean by i don't understand can any body explain
import java.io.*;
class Player {
Player() { System.out.print("p"); }
}
class CardPlayer extends Player implements Serializable {
CardPlayer() { System.out.print("c"); }
public static void main(String[] args) {
CardPlayer c1 = new CardPlayer(); //line1
try {
FileOutputStream fos = new FileOutputStream("play.txt");
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(c1);
os.close();
FileInputStream fis = new FileInputStream("play.txt");
ObjectInputStream is = new ObjectInputStream(fis);
CardPlayer c2 = (CardPlayer) is.readObject();//line2
is.close();
} catch (Exception x ) { }
}
}
explanation
line1: when this line complies it will print pc
line2:when this line complies it prints p
here superclass is not serializable but subclass is serializable then
when subclass is deserialized the constructor of superclass called and prints p but constructor of subclass are not called to retain the values stored when serialized.
A oes not compile as new cannot be used with interface
B;does not compile as incompatible types
c oes not complie as if else can return a elephant object to lion so there incompatible error occurs
d:as alpha methods may return any object i.e Lion or elephant both as soundOff() methods so no problem complies
hi,
pass by value:
passing a copy of original value.in calling method a new local variable is created and assigned the copy of value.and its scope is with in that method only i.e calling method cannot change original value.
pass by reference:
passing a copy of reference of object or variable that is the calling method creates a new reference to the original object or variable that is any changes made in it that calling method also changes original value
Both, a Sun instructor I had and Whizlabs say that when an object is constructed ("new"), default and explicit initialization of variables happens first, then the constructors are executed.

i hope they say instance variables are initialized after executing super constructors and before completing the constructor in the class .i mean after super constructors and before actual constructor in class.
class Main2
{
static String vaib()
{
return "Foo";
}
}
class Main extends Main2 {
static String vaib()
{
return "bar";
}

public static void main(String [] args)
{
Main2 m=new Main();
Main d=new Main();
System.out.println(m.vaib());------->inside complier System.out.println(Main2.vaib());
System.out.println(d.vaib());-------->inside complier System.out.println(Main.vaib());
}
}
As static mathods are independent of reference variable they are considered for classes only so they will not undergo runtime polymorphism even though you call methods with reference varibles for objects ex:m.vaib() they are replaced inside constructor by class name they refere like Main2.vaib();
class test
{
public static void main (String[] args)
{
int i = 0, j = 0, k = 0;
do
{
while (i++ < 3 )
{
System.out.print(k++);
}
} while (j++ < 3);
}
}

its a while loop inside do while loop so the code inside do while will be executed once so inner while loop prints 012 and do while runs three times but the value of i became 3 in so inner while condition fails so even though outer do while executes three time inner while loop executes only once so
output is:012
class Base{
static int value = 0;
Base(){
addValue();
}
static void addValue(){
value += 10;
}
int getValue(){
return value;
}
}
class Derived extends Base{
Derived(){
super();
addValue();
}
static void addValue(){
value += 20;
}
}
public class Test {
public static void main(String[] args){
Base b = new Derived();
System.out.println(b.getValue());
}
}
the complier inserts super() method in the derived class so once you called new derived ()this method call base() method that calls addvalue method in the base class so value=10 now and control returns to derived() methos this again calls addvalue() method so value=30 that the output
hi friends,
*calls to this() and super() cannot be in the same constructor.you can have one or other but never both.
in your program you provided a this(f) as per above rule complier will not provide super() but with out calling super you cannot initiate f so with out initiation you cannot use it in this(f) .
thank you friends i will try the methods
but is there any practical application of using private constructor.i feel its not required
how to access a constructor with private access modifier can any one explain it with a example.
i am geting a error while compiling this program
class drinks
{
private drinks()
{
System.out.println("i am abstarct constructor");
}
}
class acon
{
public static void main(String[] args)
{
drinks d=new drinks();
}
}
output:

C:\jdk1.5.0_11\bin\practice>javac acon.java
acon.java:12: drinks() has private access in drinks
drinks d=new drinks();
^
1 error

C:\jdk1.5.0_11\bin\practice>
can any body tell where can i get a java 5 complete reference ebook



(Edit: No free books here)
[ May 26, 2007: Message edited by: Barry Gaunt ]
i hope there is no problem with classpath beacuse the other statement
(import food.Car is working.
-----------------------------------------------------------------
And one more thing what a package should contain a .java file or .class file i hope its a .class file
but why the standard java package consists of .java files
can any one explain
hi Raghavan Muthu
really its not working dude you try it with same files i had i send you code also its really not working.i hope the prolem is with (.*)
class A
{
A()
{
System.out.println("inside A");
}
}
class B extends A
{
B()
{
System.out.println("inside b");
}
}
class c extends B
{
c()
{
System.out.println("inside c");
}
}
class test
{
public static void main(String args[])
{
c obj=new c();
}
}
output will be
inside A
inside B
inside c
------------------------------------------------------------
so in you progam also
addValue() will be called twice at the same time method of subclass is called as it is overridden
so you will get an out put
40