This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FinalVariable { | |
// in the instance initializer expression, or while declaration itself | |
// final <type> <variable_name> = <initializer expression>; | |
static final int finalStaticField = 25; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FinalVariable { | |
static final int finalStaticField; | |
static { | |
finalStaticField = 7; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Shape { | |
int length; | |
int width; | |
private Shape(int length, int width) { | |
length = length; | |
width = width; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Shape { | |
int length; | |
int width; | |
private Shape(int length, int width) { | |
// access member variable incase the | |
// field name and parameter name are same | |
this.length = length; | |
this.width = width; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Shape { | |
int length; | |
int width; | |
public void setLength(int length) { | |
// access the instance variable | |
this.length = length; | |
} | |
public void setWidth(int width) { | |
// access the instance variable | |
this.width = width; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Shape { | |
private void printThis() { | |
// prints invoking object | |
System.out.println(this); | |
} | |
public static void main(String[] args) { | |
Shape shape = new Shape(); | |
// print the shape reference | |
System.out.println(shape); | |
// print the shape reference inside method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Shape { | |
private int length; | |
private int width; | |
private Shape(int length, int width) { | |
// this constructs rectangle | |
this.length = length; | |
this.width = width; | |
} | |
private Shape(int length) { | |
// Constructs the square |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SuperClass { | |
int i = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SuperClass { | |
public void display() { | |
System.out.println("Super"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SuperClass { | |
public SuperClass() { | |
System.out.println("SuperClass Constr with no params"); | |
} | |
public SuperClass(int a, int b) { | |
System.out.println("SuperClass Constr with two params"); | |
} | |
} |