programming challenge in java-1
Post the correct code you have permission to take change only in public class.....
class a
{
a()
{
System.out.println("mohit kumar singh a");
}
}
class b extends a
{
b()
{
System.out.println("mohit kumar singh b");
}
}
class c extends b
{
int x;
c()
{
x=y;
System.out.println("mohit kumar singh c");
System.out.println("x= "+x);
}
}
public class f extends c
{
public static void main(String args[])
{
c t=new c();
}
}
Replies
-
sushant005
class a
Mohit am i right.
{
int y;//here we have declare y.
a()
{
System.out.println("mohit kumar singh a");
}
}
class b extends a
{
b()
{
System.out.println("mohit kumar singh b");
}
}
class c extends b
{
int x;//you do not the permission to eliminate this
c()
{
x=y;//you do not the permission to eliminate this
System.out.println("mohit kumar singh c");
System.out.println("x= "+x);//you do not have permission to eliminate this.
}
}
public class f
{
public static void main(String args[])
{
c t=new c();
}
}
Just we have to initialize y inside class a. -
sushant005
class a
Mohit am i right.
{
int y;//here we have declare y.
a()
{
System.out.println("mohit kumar singh a");
}
}
class b extends a
{
b()
{
System.out.println("mohit kumar singh b");
}
}
class c extends b
{
int x;//you do not the permission to eliminate this
c()
{
x=y;//you do not the permission to eliminate this
System.out.println("mohit kumar singh c");
System.out.println("x= "+x);//you do not have permission to eliminate this.
}
}
public class f
{
public static void main(String args[])
{
c t=new c();
}
}
Just we have to initialize y inside class a. -
Morningdot HabluOh sorry sus i have done a mistake in my question.
Check out once again. -
Kaustubh KatdarePlease always wrap your code inside
... [ /code] tags.
-
anandkumarjhaHello Mohit
as far as i know that you only created the object for the class c but didn't use it.so it might be the error.and what sushant told is also right that we should also declare y veriable inside the class A -
Morningdot Hablusince c has a constructor: c(int y) you must satisfy that constructor when you extend it. In other words r extends c but c has a constructor that requires an integer therefore r must satisfy this. You could add c() {} in class c to allow for an empty constructor or a better solution is to use super to set the constructor to a default value such as zero when constructing r: r() { super(0); } or if you wanted r(int y) { super(y); } See the Example:
class a
{
a()
{
System.out.println("mohit kumar singh a");
}
}
class b extends a
{
b()
{
System.out.println("mohit kumar singh b");
}
}
class c extends b
{
int x;
c(int y)
{
x=y;
System.out.println("mohit kumar singh c");
System.out.println("x= "+x);
}
}
class r extends c
{
r() { super(0); }
public static void main(String args[])
{
c t=new c(4);
}
} -
Manish Goyalhey mohit you had mentioned that we can make changes in only public class ie f
but here you are making changes in class c also -
Morningdot Hablu@goyal ya you are right.
Oh!! sorry guy's actually i missed int y in constructor.
Well i try to avoid this type of mistakes in my next java programming challenge.
So wait for my next challenge.
You are reading an archived discussion.
Related Posts
If the sum of the degree measures of two specific angles of triangle T is greater than the sum of the degree measures of two specific angles of quadrilateral Q,...
A collection of short and simple, creative, funny, emotional goodbye or sign-off emails to send to your colleagues and manager on your last working day (lwd) at office.
Researchers at the Computer Vision Lab at ETH Zurich, Switzerland, have developed a new technology that allows us to touch the virtual world.The technology helps researchers produce virtual copies of...
The USA Science and Engineering Festival had conducted a Jingle Competition.
And Ryan Miyakawa stood the winner by public voting.
It's really a wonderful jingle. It stirs a real passionate...
i want to make a mobile charger that can be used when moving on a vehicle
It works on the principle of a DC dynamo and the rotational kinetic energy...