0% found this document useful (0 votes)
29 views2 pages

Constructor Overloading in Java

The document discusses constructor overloading in a Java class named Box, demonstrating three constructors for different initialization scenarios. It also includes incorrect code snippets for a class with a conditional statement and loops, highlighting syntax errors and issues in the implementation. Overall, the document serves as an example of Java programming concepts related to constructors and control flow structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Constructor Overloading in Java

The document discusses constructor overloading in a Java class named Box, demonstrating three constructors for different initialization scenarios. It also includes incorrect code snippets for a class with a conditional statement and loops, highlighting syntax errors and issues in the implementation. Overall, the document serves as an example of Java programming concepts related to constructors and control flow structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

conttructor overloading

public class Box {


double width, height, depth;
int boxNo;

// constructor used when all dimensions and


// boxNo specified
Box(double w, double h, double d, int num)
{
width = w;
height = h;
depth = d;
boxNo = num;
}

// constructor used when no dimensions specified


Box()
{
// an empty box
width = height = depth = 0;
}

// constructor used when only boxNo specified


Box(int num)
{
// this() is used for calling the default
// constructor from parameterized constructor
this();

boxNo = num;
}

public static void main(String[] args)


{
// create box using only boxNo
Box box1 = new Box(1);

// getting initial width of box1


System.out.println(box1.width);
}
}

statement

public class {

int x = 50;
int y = 10;
if(x > y) {
System.out.println("Hello World");
else
system.out.println("beijesh");

}
loops

Class main
{
Public static void main(string[] args )
{
Int i=5;
// for printing
For(int i=0;i<5;i++)
System .out.println(“brijesh”);
}

while loop-------

class main
{
public static void main(string[] args )
{
int a=6;
while(a)
syatem.out.println("brijesh");
}

You might also like