GoodEmployee is defined who has ALL the following properties:
He should be married.
He should have 2 or less than 2 children.
His middle name should start with "k" but not end with "e"
The last name should have more than 4 characters
The character "a" should appear in the last name at least two times.
The name of one of his children should be "Raja"
isMarried true if the employee is married.
noOfChild the number of children of the employee.
middleName the middle name of the employee
lastName the last name of the employee.
childNames the array of the names of the children of the employee
I have a class named Base and a private variable named _hopcount i have 10 instances of class base i use _hopcount as creteria to some if but other instances edit _hopcount so i want to prevent _hopcount edit by other instances; I want to have private variable which other instances of same class can't modify it.
public class Base extends TypedAtomicActor { private int _hopcount = 0; if(_hopcount <= 3) { some code; } public function() { _hopCount += 1; } }
The term "Local variable" is related to scope. That is a local variable is one which is defined in a certain block of code, and its scope is confined inside that block of code.And a "Member variable" is simple an instance variable.
I read in a discussion forum that when local variables are declared (example code below), their name reservation takes place in memory but they are not automatically initialized to anything. On the other hand, when member variables are declared, they are automatically initialized to null by default.
Java Code: public void myFunction () { int [] myInt; // A local, member variable (because "static" keyword is not there) declared } mh_sh_highlight_all('java');
So it seems that they are comparing local variables and member variables. While I think a member variable can also be be local in a block of code, isn't it?
when we create another variable and set it equal to the first : Car c2 = c1;
we're pointing c2 at the same car object that c1 points to (as opposed to pointing c2 at c1, which in turn points at the car). So if we have code like,
Car c1 = new Car(); Car[] cA = {c1, c1, c1, c1};
are we doing the same? Are we creating four *new* reference variables, each of which points at the same car (again as opposed to pointing them at c1 itself)? I think so, but want to make sure I'm understanding this correctly.
I have a JFrame jf and JPanel jp on it. jp has five TextFields named cel1, cel2.. cel5. I wish to construct a String Cel + for loop index and run a for loop to reset the values of all the text fields using a single statement such as cel1.SetText("abc"). Similar things can be done in foxfro. How does one do it in java?
I can understand result 3 is because of an upcast from short to int, since FunWithOverloading will not have a overloaded method with short now. However, what is happening with result 4? Shouldn't it call methodA of the subclass with the argument type short? If its because I have declared the reference variable, derived, of the type FunWithOverloading, then how come the first result correctly picks the overloaded method of the sub class?
class FunWithOverloading{ void methodA(int x){System.out.println("Integer method " + x);} void methodA(short x){System.out.println("Short method " + x);} //line 3 } class OverloadedSubClass extends FunWithOverloading{ void methodA(short x){System.out.println("Sub class short method " + x);}
how objects relate to classes and how you can create and re-use object types.on that point, but this has me baffled. I most certainly do not have a firm grasp yet on passing things to and from methods that just makes my head hurt. SO anyway I tried out one of the code examples:
/* ElectricGuitar.java */ class ElectricGuitar { String brand; int numOfPickups; boolean rockStarUsesIt;
[code]...
But I just realized this thing has no main method and only one class defined.....so I guess I just tried to compile.
I am trying to understand the concept of Generics in java. In the introduction to Generic Types, this example is given:
Java Code: public class Box { private Object object; public void set(Object object) { this.object = object; } public Object get() { return object; } } mh_sh_highlight_all('java'); "Since
Since its methods accept or return an Object, you are free to pass in whatever you want, provided that it is not one of the primitive types." - I understand this.But then it has been changed to a generic class:
Java Code: /** * Generic version of the Box class. * @param <T> the type of the value being boxed */ public class Box<T> { // T stands for "Type" private T t;
public void set(T t) { this.t = t; } public T get() { return t; } } mh_sh_highlight_all('java'); "
As you can see, all occurrences of Object are replaced by T. A type variable can be any non-primitive type you specify: any class type, any interface type, any array type, or even another type variable."We can use any type in place of an Object, because Object is a superclass of all classes. But T (or any other class) is not a superclass of all classes. So how do we justify any class being used in place of a random T or any other class?
public class AutoBoxingExample { public void add(Integer intVal){ System.out.println("Wrapper"); } public void add(int value){ System.out.println("Primitive"); } public static void main(String[] args) { AutoBoxingExample auto = new AutoBoxingExample(); auto.add(12); } }
The output is "Wrapper". What would be the reason behind it?
import javax.swing.JOptionPane; public class Input { public static void main(String[] args) { int user; user = JOptionPane.showMessageDialog(null, "Enter Your Age""); ERROR IS HERE if(user <= 18) { JOptionPane.showMessageDialog(null, "User is legit"); } else { JOptionPane.showMessageDialog(null, "User is not legit"); } } }
I'm getting this error message :
incompatible types: void cannot be converted to int
I need to write a class that represents and image of RGB pixels. This class uses a two-dimensional array of object type that represents R,G and B values.
When I compile the class it completes successfully. However, when I try running a "tester" class , I'm encountering errors in a few methods. I've been trying it out for 2 days now, but unsuccessfully thus far..Those method are : rotating the image by 90 degrees clockwise (and vice versa , but I just use clockwise method 3 times for that) , shifting the image sideways, and shifting the image up/down..
I've attached the whole source code for the class , and the list of errors I get when I try to run my tester. URL...
I am looking at a snippet of code in my "learning Java 4th edition" by Orielly and there is a small snipped of code which says:
Java Code: Date date = new Date(); List list = new ArrayList(); list.add( date ); ..
Date firstElement = (Date)list.get(0); // Is the cast correct? Maybe. mh_sh_highlight_all('java'); so I am typing the same thing in my compiler in a small Driver class and for some reason I have an error and Im dumbfounded...
import java.util.*;public class DebugSix { public static void main(String[] args) {
ArrayList<String>products = new ArrayList(); products.add("shampoo"); products.add("moisturizer"); products.add("conditioner"); Collections.sort(products);
[Code] ....
I am using netbeans and getting errors for display(); and size(); it is telling me the errors are :
for the display error, "method display in class DebugSix cannot be applied to given types; display();" and for the size() is : "cannot find symbol System.out.println(" The size of the list is " + size());"
int a, b, sum; System.out.print("the sum is"); Scanner in = new Scanner(System.in); a = in.nextInt(); b = in.nextInt(); Sum = a + b; System.out.println("the sum us" + sum);
in "sum = a+b" its says "incompatible types: int cannot be converted to boolean" I dont understand why